Simple, silly question...
Okay, I have this situation that I hope someone here can help me out on.
Basic Java question basically:
I have a server listing on port x for client connections. It receives and
accepts 2 client connections (though 2 is only an abitrary number and could
easily be 10 or 100 or whatever). Now, client A wants to send a message
to Client B. So the person running Client A types the message in the space
provided and presses SEND. How do I get the message to client B?
Is this as simple as it sounds and I just keep track of the names of each
and every socket and send the message to the appropriate one or is it more
complicated than that. Any help would really be appreciated. I would imagine
that this functions similar to the Unix Talk utility...
Re: Simple, silly question...
as i see ur server is multithreaded(it accepts more than one client simultanoeously)
so for each client the server accepts the incoming connection then it assigns
this client a worker thread that handles the connection.
First i suggest when u create the worker thread for each client u name the
thread ( using the Thread constructor ) by the name of the connected client.
Now when client A sends a message to B the server will be listening to all
clients. A sends a msg the server rcvs it then the server should enumerate
all threads that are running in the run-time environment and calls some member
function of the Thread inherited class ( te worker thread i mean) ... this
function sends the msg to the client that owns that thread at ther server.
another option is when sending the message from client A the client may include
the recepients name and that is the name of the working thread for the recepients
client. So when the server enumerates the working threads it only calls the
previously mentioned member function for onyl that client (indicated by his
worker thread name)....
It may seem a little compliacted but it's very effecient and IT WORKS
I hope that'll help