471,316 Members | 1,476 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

Problem connecting Server/Client, TCP

Hi guys! My first post here is ofcourse a little problem of mine! =) ive been looking pretty mutch everywhere, asking my proffesor and such, and we cant figure this out at all. I even analyzed the network trafic with Wireshark to see what was going on. No luck. So now im turning to you hardcore guys here! =)

Well to the problem. Im doing a really, REALLY simple chat client. (intending to control the mouse over ethernet). Where everything stops is when im trying to connect to the server.

On the client machine im running Vista using standard IPv6, and the Server im running XP Pro with IPv6. When launching the code below i can see from the network analyzing that it is actully sending packets and reciving to and from the server machine.

Then it gives me the most odd explenation ever.
"No connection could be made because the target machine activley refused it".

Ive tried to open up the network as mutch as possible to do a trial and error thing, but still no luck.

I dont even need to have my server app up and running. it still gives me the same message.

This is the Client code:

Expand|Select|Wrap|Line Numbers
  1. public void RunClient()
  2. {    
  3. try    
  4. {        
  5. Client = new TcpClient();        
  6. Client.Connect("192.168.1.33", 50000);        
  7. outputStream = Client.GetStream();        
  8. Writer = new BinaryWriter(outputStream);    
  9. }        
  10. catch (Exception e) { MessageBox.Show(e.ToString()); }    }}
  11.  
  12.  
  13. This is the servercode:
  14.  
  15. private void RunServer()
  16. {    
  17. TcpListener listener;        
  18. try    
  19. {        
  20. IPAddress local = IPAddress.Parse("127.0.0.1");        
  21. listener = new TcpListener(local, 50000);                        
  22. listener.Start();        
  23. while (true)        
  24. {            
  25. Connection = listener.AcceptSocket();            MessageBox.Show("Someone got connected."); ...
  26.  
The servercode doesnt even reach the MessageBox.Show code. Seems like it is something external that is keeping the connection away. Anyone have any idea or could kick me in the right direction?

Thanks in advance for occupying your time =)
Jun 21 '07 #1
6 1820
RedSon
5,000 Expert 4TB
...So now im turning to you hardcore guys here at The Code Project
I'm not sure you have the right place. This is TheScripts not The Code Project.

When you step through your code at what point does it break down? Perhaps you do not have any timeouts for your connections so the server never drops the first connection if it does not receive a packet. You should also make sure that your server side is multi threaded so that it can accept more then one connection from a client.

Can you let me know at what point it fails like what line number? And also try to post up your locals. Maybe that will help?
Jun 21 '07 #2
hehe i saw that =) changed it ;)
either way.
im using a threaded server side since i thought it would be some kind of problem with that. but nope, no luck.

Expand|Select|Wrap|Line Numbers
  1.         private Socket Connection;
  2.         private Thread readThread;
  3.  
  4.         private NetworkStream socketStream;
  5.         private BinaryReader Reader;
That is the locals for the server.

But it seems not to be the problem since i can shutdown my server app and still it gives me the same error.

=(

it fails on line 6, clientside
Jun 21 '07 #3
TRScheel
638 Expert 512MB
hehe i saw that =) changed it ;)
either way.
im using a threaded server side since i thought it would be some kind of problem with that. but nope, no luck.

Expand|Select|Wrap|Line Numbers
  1.         private Socket Connection;
  2.         private Thread readThread;
  3.  
  4.         private NetworkStream socketStream;
  5.         private BinaryReader Reader;
That is the locals for the server.

But it seems not to be the problem since i can shutdown my server app and still it gives me the same error.

=(

it fails on line 6, clientside
I believe its your firewall. I had the same issue when coding something similiar.
Jun 21 '07 #4
RedSon
5,000 Expert 4TB
I think you might be using the wrong method call.

http://msdn2.microsoft.com/en-us/lib...52(VS.71).aspx
Jun 21 '07 #5
TRScheel
638 Expert 512MB
I think you might be using the wrong method call.

http://msdn2.microsoft.com/en-us/lib...52(VS.71).aspx

I dunno, I used nearly the same code and it worked for me
Jun 21 '07 #6
Plater
7,872 Expert 4TB
Then it gives me the most odd explenation ever.
"No connection could be made because the target machine activley refused it".
That message usually occurs when the client can FIND the server (ie the server responds with "yeah Iexist") and means you made it through the firewall*. But the port you are connecting on does not have anyone listening on it.
Say I have a server at 192.168.1.45 and my program is listening on port 5000 and nothing else listening.
If I tell my client to connect to 192.168.1.45:5001 and there is no firewall issues it will tell me "connection actively refused" because it could find my server but there was nothing listening on that port.

* Firewalls generally will NOT respond with anything if the port is not opened, thus having the "connection timed out" in an attempt to trick possibly malicious clients from knowing there is a computer there.

NOW THEN, I just double-checked and saw another problem:
Expand|Select|Wrap|Line Numbers
  1. IPAddress local = IPAddress.Parse("127.0.0.1");        
  2. listener = new TcpListener(local, 50000);                        
  3. listener.Start();   
  4.  
This is only listening on localhost's ip (127.0.0.1) which means ANY other address will not connect to it.
You will want to use IPANY (it's a static under like IPAddress I think)
Jun 21 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Dmitry Akselrod | last post: by
1 post views Thread by Thomee Wright | last post: by
reply views Thread by Suresh | last post: by
reply views Thread by NoaGross | last post: by
10 posts views Thread by mairhtin o'feannag | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.