0

I am trying to write a piece of software that

  • accept simple UDP messages (text strings) from simple UDP client,
  • opens connection to another server and forwards messages to it
  • listens for that server reply and
  • forwards that reply back to the client.

So it is a simple intermediate server.

To visualise the communication:

Client <---> Intermediate Server <---> "Real" Server

The client connects to the Intermediate but has no idea that the message it sends is being forwarded to another server, or that it's reply is actually from another server. As far as the client cares it the Intermediate server is the real server.

I am trying to use Java's DatagramChannel for this, but not quite sure how to correctly do this in a non-hack way. Do I use two DatagramChannels? One for Client--Intermediate and the other for Intermediate--Real Server?

An general outline of approach would be appreciated, particularly if I need to open a socket every time I need to forward a message from the Intermediate to the Real Server, or if I can keep that socket open somehow.

6
  • I would use persisted TCP connections all the way. But if you have to use UDP, I would use DatagramChannel. Commented Mar 31, 2012 at 7:55
  • So I can somehow use just one DatagramChannel when the intermediate needs to talk to client and server? Commented Mar 31, 2012 at 10:03
  • OK so I have DatagramChannel for the client facing side of the Intermediate server which is bound to a specific port so the client knows how to connect to it, and another DatagramChannel for the link to the "real" server from the Intermediate. Does that make sense? It seems to work! Commented Mar 31, 2012 at 11:09
  • 1
    If that works you could have the client send a packet to the final server. Commented Mar 31, 2012 at 13:44
  • Thank you Peter, could you please be a bit more specific in your answer? Commented Mar 31, 2012 at 22:12

1 Answer 1

1

You only need one datagram socket for this, and you can keep it open for the life of the process.

Sign up to request clarification or add additional context in comments.

2 Comments

So I can use one socket or datagram channel object on intermediate to talk with client and real server?
@xingyu I've already said exactly that. Why are you asking me to confirm my own statement?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.