Hi guys,
I have a class that listens to one port using ServerSocket. After
successfully receiving a packet, can i reply back to the client, in a
way that the client do not have to listen for incoming packets.
Thx in advance.
tom fredriksen - 16 Feb 2006 09:15 GMT
> Hi guys,
>
> I have a class that listens to one port using ServerSocket. After
> successfully receiving a packet, can i reply back to the client, in a
> way that the client do not have to listen for incoming packets.
If I understand your question correct, you are asking if the client can
get a reply without having to listen on a port of its own for the reply?
If that is the case then yes, in the jdk api page for the ServerSocket
class it states that it is a TCP socket, which means that the client
only has to do a read of the socket to get a reply.
Or are you perhaps asking of you can come back to the socket at a later
time to read the reply?
/tom
Chris Uppal - 16 Feb 2006 10:14 GMT
> I have a class that listens to one port using ServerSocket. After
> successfully receiving a packet, can i reply back to the client, in a
> way that the client do not have to listen for incoming packets.
Do you mean: without the client having to create, and listen on, a ServerSocket
of its own ? If so then the answer is that when a ServerSocket recieves a
connection, that creates a two-way stream between the client and the server.
The server can send data back to the client on the newly created Socket. The
client can read that data from the Socket connection that it opened to the
server.
If you mean something else, then I'm afraid you'll have to clarify what you
mean.
-- chris
JPractitioner - 16 Feb 2006 21:15 GMT
Thanks a lot guys. Both answer are brilliant! I ve been enlightened.
Thanks again.
by the way, i was thinking to make a listener for the client as well.
but i'm glad that i asked here.