1

Ok so I've found out Sockets are not serializable... so I cant pass them over TCP...

My problem is I have a homework assignment where I have 10 servers that must listen on one socket(lets call it request). For input from any of x number of clients that write to that socket. Then after one of the server processes reads a message from request it must communicate with that client over its own socket...

I tried making each server socket and the request socket on the server side, then passing those to the clients when they connected to the server... but this doesn't work...

Any tips on how I might do this? Having TCP not be 1-1 is really toying with me here.

2
  • 3
    No, it doesn't make any sense to "pass" sockets. Commented Sep 30, 2011 at 0:39
  • 3
    I don't understand what you mean by "Having TCP not be 1-1". TCP definitely is a point-to-point protocol. Commented Sep 30, 2011 at 0:41

2 Answers 2

3

Passing a socket over a TCP connection is like trying to pass a telephone over a telephone call, or trying to fax your fax machine. What you need to do is organize another connection between the parties concerned.

EDIT: In fact your assignment as stated doesn't even make sense:

I have 10 servers that must listen on one socket(lets call it request).

That's not even correct terminology. Servers listen at ports, not sockets, and 10 servers listening at one port is impossible. They must each have their own port.

For input from any of x number of clients that write to that socket.

See above. Clients don't write to 'that socket'. They create their own socket that is connected to the server port, and they write to that.

Then after one of the server processes reads a message from request it must communicate with that client over its own socket

If the server has received a connection from a client it already has a socket representing its endpoint to that connection. So all the server has to do is write the response back to the same socket it read the request from.

In short you have a major terminology problem, but you don't have a software problem at all.

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

2 Comments

This question is blowing my mind really... it is twisting everything I've known about proper server design. We are using sockets as a message passing construct. The term server is being used loosely I guess. Basically n Server processes are supposed to read from the same TCP stream. And somehow m clients are supposed to be able to write to this stream. I've given up on the second part because I don't think it is possible with TCP.
@Michael if that's what the question really calls for, it is complete and utter nonsense and should be returned to sender, or put out with the garbage on Thirsday morning. Early. Howewer I find that quite impossible to believe. I suggest you edit your question to include the actual text of the question.
0

Passing sockets seems crazy to me. If you're trying to write a better server, you'll have a hard time beating Netty. I'd recommend giving it a look.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.