Problems with UdpClient
-
I have 2 computer i a LAN, witch is connected to the internet. Comp1. Ip = 192.168.0.195 Comp2. Ip = 192.168.0.163 My router is set up to forward port 12000 to comp2. Comp1 acts as a server. It sends data using UDPClient.
'Uses the IP address and port number to establish a socket connection. udpClient = New UdpClient Dim ipAddress As IPAddress = Dns.Resolve("my internet IPaddress").AddressList(0) Try udpClient.Connect(ipAddress, 12000) Catch ex As Exception Console.WriteLine(ex.ToString()) End Try udpClient.Send(Data, Data.Length)
Comp2 acts as a client. It receives data using UDPClient.Dim receivingUdpClient As New UdpClient(12000) Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0) Do Try Data = receivingUdpClient.Receive(RemoteIpEndPoint) ... ....
Comp2 doesn’t receive anything. BUT... if Comp1 is setup like this'Uses the IP address and port number to establish a socket connection. udpClient = New UdpClient Dim ipAddress As IPAddress = Dns.Resolve("192.168.0.163").AddressList(0) Try udpClient.Connect(ipAddress, 12000) Catch ex As Exception Console.WriteLine(ex.ToString()) End Try udpClient.Send(Data, Data.Length)
Then it works. The only changes I made is, instead of using my internet adr. I used my locale adr. Any idea why??? -
I have 2 computer i a LAN, witch is connected to the internet. Comp1. Ip = 192.168.0.195 Comp2. Ip = 192.168.0.163 My router is set up to forward port 12000 to comp2. Comp1 acts as a server. It sends data using UDPClient.
'Uses the IP address and port number to establish a socket connection. udpClient = New UdpClient Dim ipAddress As IPAddress = Dns.Resolve("my internet IPaddress").AddressList(0) Try udpClient.Connect(ipAddress, 12000) Catch ex As Exception Console.WriteLine(ex.ToString()) End Try udpClient.Send(Data, Data.Length)
Comp2 acts as a client. It receives data using UDPClient.Dim receivingUdpClient As New UdpClient(12000) Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0) Do Try Data = receivingUdpClient.Receive(RemoteIpEndPoint) ... ....
Comp2 doesn’t receive anything. BUT... if Comp1 is setup like this'Uses the IP address and port number to establish a socket connection. udpClient = New UdpClient Dim ipAddress As IPAddress = Dns.Resolve("192.168.0.163").AddressList(0) Try udpClient.Connect(ipAddress, 12000) Catch ex As Exception Console.WriteLine(ex.ToString()) End Try udpClient.Send(Data, Data.Length)
Then it works. The only changes I made is, instead of using my internet adr. I used my locale adr. Any idea why???I would double check the router configuration to make sure that it is indeed sending the information to the correct local IP address. Also, make sure that the default gateway on the machines in the local IP address of the router. And, finally, do you have any firewall software running on the machines? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
I would double check the router configuration to make sure that it is indeed sending the information to the correct local IP address. Also, make sure that the default gateway on the machines in the local IP address of the router. And, finally, do you have any firewall software running on the machines? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
I can see the data is ariving at the client... LAN-connection in the traybar but the program doesn't receive the data. NetLimiter shows that the client program has NO connections.
-
I can see the data is ariving at the client... LAN-connection in the traybar but the program doesn't receive the data. NetLimiter shows that the client program has NO connections.
Once again, do you have a firewall running on that machine? If so, disable it and see what happens... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Once again, do you have a firewall running on that machine? If so, disable it and see what happens... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
No firewall's at all. and turned off in router. Is it cuz i'm sending and receiving on the same internet ip-address? (just for testing) :confused:
-
No firewall's at all. and turned off in router. Is it cuz i'm sending and receiving on the same internet ip-address? (just for testing) :confused:
I've got a strange feeling about this one. Try your code from a test machine outside your router. Try it on a friends machine from his/her house connecting back to your internet IP address. I get the feeling that either the router is still misconfigured somehow, or there's something you haven't told us about your UDP connection. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
I've got a strange feeling about this one. Try your code from a test machine outside your router. Try it on a friends machine from his/her house connecting back to your internet IP address. I get the feeling that either the router is still misconfigured somehow, or there's something you haven't told us about your UDP connection. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
ok, thanks. I'm making a small prog witch sends data to my internet ip every 3 sec. Then running the prog from another computer (diff. IP). And a little prog. witch try's to receive the data, and running it from my computer.
-
I've got a strange feeling about this one. Try your code from a test machine outside your router. Try it on a friends machine from his/her house connecting back to your internet IP address. I get the feeling that either the router is still misconfigured somehow, or there's something you haven't told us about your UDP connection. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Hmmm....:wtf: The only code that works is:
Dim rxSocket As Socket = Nothing Dim RecvBytes(1000) As Byte Dim RemoteEP As New IPEndPoint(0, 0) Dim myCallback As New AsyncCallback(AddressOf OnReceive) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load rxSocket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) RemoteEP = New IPEndPoint(IPAddress.Any, 12000) rxSocket.Bind(RemoteEP) rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length, _ SocketFlags.None, RemoteEP, myCallback, Nothing) End Sub Public Sub OnReceive(ByVal ar As IAsyncResult) Dim iBytes As Integer Try Catch e As SocketException MsgBox(e.Message) Exit Sub End Try ListView1.Items.Add(System.Text.Encoding.UTF8.GetString(RecvBytes)) iBytes = rxSocket.EndReceiveFrom(ar, RemoteEP) rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length, _ SocketFlags.None, RemoteEP, myCallback, Nothing) End Sub
But thanks for your help