I am writing a client/server program. currently the server and the
client are running in the same computer. the client used to connect
fine to the server with the following code:
Dim ipHostInfo As IPHostEntry = Dns.Resolve(Dns.GetHostName)
Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
Dim remoteEP As New IPEndPoint(ipAddress, port)
' Create a TCP/IP socket.
client = New Socket(AddressFamily.InterNetwork, _
SocketType.Stream, ProtocolType.Tcp)
' Connect to the remote endpoint.
client.BeginConnect(remoteEP, AddressOf ConnectCallback,
client)
however when I change the first line to the following:
Dim ipHostInfo As IPHostEntry = Dns.GetHostByAddress("192.168.1.2")
where 192.168.0.2 is the ip address of the local machine as well
I am getting the following exception
system.net.sockets.socketexception: the requesed name is valid and was
found in the database, it does not have the correct associated data
being resolved for
at systemm.net.dns.gethostbyaddress(IPAddress address)
at system.net.dns.gethostbyaddress(string address)
at chat.tech..ctor((frmchat&frm)
I tried changing the first the line to the following
Dim ipHostInfo As IPHostEntry =
Dns.GetHostByAddress(Net.IPAddress.Parse("192.168. 1.2"))
got the same error message above
I also tried the following code:
Dim ipAddress As IPAddress = Net.IPAddress.Parse("192.168.1.2")
'ipHostInfo.AddressList(0)
Dim remoteEP As New IPEndPoint(ipAddress, port)
' Create a TCP/IP socket.
client = New Socket(AddressFamily.InterNetwork, _
SocketType.Stream, ProtocolType.Tcp)
' Connect to the remote endpoint.
client.BeginConnect(remoteEP, AddressOf ConnectCallback,
client)
connectDone.WaitOne()
I got the following error
system.net.socket.socketexception: a connection attempt failed because
the connected part did not properly respond after a period of time or
established connection failed because connected host has failed to
respond
at system.net.sockets.socket.endconnect(iasyncresult asyncresult)
at chat.tech.connectcallback(iasyncresult ar)
Am I missing anything?
Thanks