473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 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 1944
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

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

Similar topics

0
by: Ali | last post by:
I'm trying to write a really basic chat program that allows 2 client programs to send messages to each other via a server. I've managed to write the code so that both clients can connect to the...
1
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for...
3
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library....
0
by: richard | last post by:
OS: Winxp and Win2003 Visual Basic.NET 2003 MS-SQL Server 2000 hey all I am a newbie in vb.net but i have managed to build a simple chat server in vb.net using socket and a client connecting...
1
by: Thomee Wright | last post by:
I'm having a problem with a pair of applications I'm developing. I have a server application which interacts with several instruments, and a client app which connects to the server and provides a...
0
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2...
5
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2...
0
by: NoaGross | last post by:
Hi, I'm relly new in java and I have a problem. I'm using java applet. When using http all ok, but when trying to use https i get: Java Plug-in 1.5.0_10 Using JRE version 1.5.0_10 Java...
9
by: darthghandi | last post by:
I am trying to create a server application using asynchronous sockets. I run into a problem when I try to connect to my server using a non-.net program. I can establish the connection, and send...
10
by: mairhtin o'feannag | last post by:
Hello, I'm having problems connecting to my new v9 db box. The pertinent information is below: DB2_db2inst1 60000/tcp DB2_db2inst1_1 60001/tcp DB2_db2inst1_2 60002/tcp DB2_db2inst1_END...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.