Sign in to follow this  

One socket two ports with UDP

This topic is 3620 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
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

This topic is 3620 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this