Jump to content
  • Advertisement
Sign in to follow this  
Woltan

One socket two ports with UDP

This topic is 3908 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Heyas folks, I am trying to establish a UDP connection between three different programs. Dont ask me why I have to do this, sometimes you gotta cope with strange things. I have two computers where those three programs run on. Machine #1, which runs program #1, sends packages to machine #2, which runs program #2 and #3. Program #2 should receive those packages on one port and send it via another port to program #3 which eventually should receive those packages of program #2. My main work is on program #2 which kind of translates those incoming packages into another format. Program #2: Receiving the packages on port A is not much of a problem, however when it comes to receiving on port A AND sending on port B problems arise. My first question is: Is it possible to receive and send on two different ports using UDP? I would almost instantly say yes, but since I've been trouble shooting for the last 2hours I would like to confirm that. second question: do you use the very same socket, when you want to receive data on port A and send data on port B? Or do you have to initialize another socket? I hope some of you can help me with this one! Thx in advance for any hint/link/tutorial/article that you have covering that material cheerio Woltan

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Is it possible to receive and send on two different ports using UDP?


Yes.

Quote:
do you use the very same socket, when you want to receive data on port A and send data on port B? Or do you have to initialize another socket?


If you have access to lower level, and run-time permissions to do so, you could construct custom packet that would allow you to send (only send) packets as if they originated from any port, even unbound one, but technically that's IP spoofing. Libpcap might allow that.


But for any and all practical purposes, use two sockets. You have a basic UDP proxy, that's how it's done.

Quote:
Thx in advance for any hint/link/tutorial/article that you have covering that material


Create two server sockets, bind them to desired ports on localhost. Keep recv-ing on one, send-ing on another.

Share this post


Link to post
Share on other sites
you can do that.
but,basically,you should receive data from one socket and send data by another socket,not the same socket!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!