By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

Socket problem

P: n/a
rs
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
rs
Sorry guys for the silly question. I had the wrong IP address :S
my assigned ip was 192.168.0.2 :S
I have wasted 2 days in such a silly problem

Nov 21 '05 #2

P: n/a
ur code isn't doing nothing...
i suggest u www.pscode.com
search chat in vb.net u will get both server and clinet source code.
regards

rs wrote:
Sorry guys for the silly question. I had the wrong IP address :S
my assigned ip was 192.168.0.2 :S
I have wasted 2 days in such a silly problem


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.