Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am having problem sending UDP packets over the internet. I followed the example found at https://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2 and I was able to send UDP packets on the local host (client and server are on the same computer). I was also able to send UDP packets to other computers on the same network using the private IP from router (192.168.xxx.xxx). But when I want to send the UDP packet over the internet, the packets will not get to the destination computer. When I do a google search on what might be the cause, I discovered the following:

1. To access a computer over the internet, you must connect to the "public" IP address of the computer.
2. You need to enable port forwarding on your router to redirect incoming packets on the public IP address to the computer's private IP address

I did everything and still, it refuse to work. I am sending out UDP packets tothe public IP address of my internet and I have also done port forwarding ony router. Although I am not too sure if the setting I did was correct, but there are four required fields for the port forwarding settings which I set as follows:
Remote host: I left it blank
Remote port range: 54321-54321
Local host: 192.168.1.13 (the receiving computer)
Local port: 54321
Protocol: TCP/UDP

And I saved the settings. So, when I send out UDP packets on the sending computer, it did not arrive on the receiving computer. I don't know why. Please help me out.
Posted

1 solution

If you're doing the sending you don't do the port forwarding on your machine. You do it on the receiving end.

If you're trying to send data in both directions between two machines, BOTH ends have to setup port forwarding to their respective internal IP addresses and ports.


You're sending data to a public IP and Port combination. The router at that address has to forward UDP traffic on the port you're using to the internal private IP and Port that your target application is listening on.
 
Share this answer
 
Comments
Joeadeoye 15-Apr-15 1:49am    
Yes sir. I did exactly as you said. I configured port forwarding on the receiving computer and my vb.net application is listening on port 54321. And it is still not working. Please help me
Dave Kreskowiak 15-Apr-15 9:29am    
That's about all I can tell you as there's really nothing else to configure. Either that configuration is wrong and/or your code is wrong somehow. But, seeing as how you said the code works locally, the port forwarding configuration on the other end appears to be wrong.
Joeadeoye 17-Apr-15 5:31am    
What I discovered was that the problem was because both computers are on the same network. So I "guess" the router is "not allowing" the computers on it to connect to its public IP address since the computer I want to reach is still on the same network, so the router is telling me indirect to use private IP instead. It seems public IP can only be connected to from another network and not the same network
Dave Kreskowiak 17-Apr-15 8:32am    
That is hardly "over the internet".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900