views:

26

answers:

1

hi, my computer configured to have automatically ip address and when i use ipconfig /all command that shows something like below:

Windows IP Configuration

PPP adapter Broadband Connection:

Connection-specific DNS Suffix . : IPv4 Address. . . . . . . . . . . : 95.38.95.204 Subnet Mask . . . . . . . . . . . : 255.255.255.255 Default Gateway . . . . . . . . . : 0.0.0.0

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::64d7:e4ee:ba7e:1ede IPv4 Address. . . . . . . . . . . : 192.168.72.198 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.0.1

i should use 95.38.95.204 or 192.168.72.198 as ip address for server and client?

when i use 192.168.72.198, server connect successfully but client throw an SocketException like below

 var tcpServer = new TcpClient();
 tcpServer.Connect(new IpAddress("192.168.72.198"), 1986);

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.72.198:1986

i used this articles on geekpedia at http://www.geekpedia.com/tutorial239_Csharp-Chat-Part-1---Building-the-Chat-Client.html

thanks if anybody can help me

+1  A: 

If you are testing it on your own computer you can use 127.0.0.1 or "localhost".

You should use the IPv4 address generally (192.168.72.198).

It sounds like you don't have your server already running on that socket.

Graphain
thanks, but article author said we can use 192.168.72.198 and this should be works properly. but on my computer not. i need to change any section on network setting? i'm using windows 7, ilso when i turn off my adsl modem and get ipconfig command, result is nothing and says Media disconnected
Sadegh
I agree with Graphain; the most likely reason for that error is that your server process is not running. You can test this by running `netstat -a` and looking for port `1986` in a `Listening` state. Regarding your comment, you need a network to have a network address; this is why 192.168.72.198 goes away when you turn off your modem.
Stephen Cleary
@Stephen when i run netstate -a on cmd that shows this: **TCP 192.168.72.198:1986 Sadegh-PC:0 LISTENING** but still my client can't connect to this ip:port and SocketException was thrown(timeout and connection failed)
Sadegh
Try using `IPAddress.Any` for your server's IP. That's the standard practice for servers.
Stephen Cleary
oh man that great but still client can't connect
Sadegh
It might be listening, but is it actually responding? If you do `telnet 192.168.72.198 1986` in a command prompt, and pretend to be the client and send whatever the client would by typing it and hitting enter what happens?
Graphain