a connection problem  
Author Message
AlexBB





PostPosted: .NET Framework Networking and Communication, a connection problem Top

I am trying to incorporate a sample demo into my C# app. This demo has been provided by a server that supplies stock market data. They say it has been written by a user and basically tested by them. The code of course is provided with no warranty. It does not work for me the way they say it should and I have a conceptual problem with the way they use classes. I want please someone make a review and tell me if it should work conceptually.

private void pushLogin_Click ( object sender, System.EventArgs e )
{
try
{
FormLogin FormLogin = new FormLogin ( );
{
// Create a TCP/IP socket.
mClient = new Socket ( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );

System.Net.IPAddress ipAdd = System.Net.IPAddress.Parse ( "127.0.0.1" );

int port = Convert.ToInt32 ( FormLogin.textBoxPort.Text ); // they use port 16240
IPEndPoint endPoint = new IPEndPoint ( ipAdd, port );

// Connect to the remote endpoint.
mClient.Connect ( endPoint ); // here the code breaks down at runtime.

There is another form: FormLogin where you click a button and a port number in textbox. They recommend port 16240. They also recommend using IP address 127.0.0.1 which is my local machine. There is an API provided by them which is running on my machine. It is doing fine. I see real-time data in a GUI.

I do not understand how a Class Socket.Connect (Endpoint) statement can connect anything to. It is supposed to connect to a remove machine, not local one. Am I wrong

I get an error message: No connection could be made because the target machine actively refused it.

OK, I know their IP address. I've decided to make a remote connection. I get the same error code.
I try a different IP address: www.yahoo.com with port 80 - connection is established. I try www.yahoo.com with port 16240 - it seems the connection is made but terminated in a minute or so because the remote server did not respond with confirmation.

I try to argue with the guy over at data provider and he says that the connection has nothing to do with his server. All they do is to lent me their API and I have to connect to my IP and my port.

I also tried to use IP address 10.1.10.1 which is my cable modem's IP address - the same result.
I also tried to use my own static IP address - the same error code--the target machine actively refuses it.

What can I do

I would appreciate an explanation.

Thanks.




.NET Development2  
 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, a connection problem Top

The error you are getting says that there is not Server Socket listeing on specified Port and IP Address. So Clear!

You are trying to connect to 127.0.0.1 you get the same error because there is not server Socket is listening on that port on your computer. You code is all fine and for sure it must run.

Try to make a listeing socket on 127.0.0.1 and the same port which you are using to connect. Run the Server application and then try to connect from the client application. It must run fine. And then make sure Listening socket is running on their server and other clients are successfully being connected to that machine. If all other clients are connecting sucessfully then try to use some other computer to test the application may be your Firewall is blocking connection.

I hope all above information will be of help.

Best Regards,



 
 
AlexBB





PostPosted: .NET Framework Networking and Communication, a connection problem Top

"I hope all above information will be of help."

Greatly. It gives me food for thought.

Thank you very much.