Java: Sending sockets over sockets? (7)

1 Name: #!/usr/bin/anonymous : 2009-09-21 23:06 ID:i6mxgjFG

I'm working on a simple Distributed Hash Table implementation. I would like to have each node in the network have two sockets, a client socket for sending things, and a server socket for receiving things.

My idea was that when node A connected to node B, the pseudocode would be something like this:

node A's client requests connection to node B's server
node B accepts
node A sends its own server to node B
node B's client connects to node A's server

Afterward, node A and node B should each have two client-server connections, allowing 2-way communication.

I tried to implement this by sending the ServerSocket over an ObjectOutputStream, but I realized that this was definitely the wrong direction. ServerSockets aren't serializable, for one thing. So, what's the best way to go about achieving a two-way connection between the two nodes?

2 Name: #!/usr/bin/anonymous : 2009-09-22 02:28 ID:WvrvWVit

Can't do that Fox.
The socket is a descriptor for an open file handle on your machine. The other machine can't use it.

3 Name: #!/usr/bin/anonymous : 2009-09-22 10:52 ID:Heaven

A connection is two-way. You can both read and write to it. What's the point of having two connections to support two-way communication?

4 Name: #!/usr/bin/anonymous : 2009-09-22 21:28 ID:K3+TQnaR

>>3
what if, thay aren't realy connected?

5 Name: #!/usr/bin/anonymous : 2009-09-23 04:35 ID:xxw8hg7E

>>3
If you try to have both an output and an input stream over one socket, it doesn't work. Synchronization issues.

Anyway, I figured out the obvious solution. Just have Node A send host/port info to Node B after it connects, then Node B knows how to connect to Node A's server. Which is all I really needed to begin with; I was making things more complicated than they needed to be.

6 Name: #!/usr/bin/anonymous : 2009-09-23 07:46 ID:WvrvWVit

I suspect you are still making things more complicated than they need to be. Are you trying to use UDP or TCP?

TCP is by definition two way and should always stay in sync unless you or the library you are using is doing something really retarded.

UDP is connectionless and Does Not Work That Way (unless you have some library that does extra stuff to hide the connectionless nature of UDP from you)

7 Name: #!/usr/bin/anonymous : 2009-09-23 10:52 ID:Heaven

OP I think it's time you make a post explaining exactly what you're trying to do. Don't tell us what you think the solution is, just state the problem, and avoid ambiguity.

For example, you're talking about 'both' an output and input stream. Presumably you mean both output and input operations at the same time. How do you do this? Presumably threads. But you need to clarify all this yourself, I can't go on assuming everything.

This thread has been closed. You cannot post in this thread any longer.