|
-
May 24th, 2008, 02:50 PM
#1
Thread Starter
New Member
Messenger (Client/Server)
Hi,
i do not have pretty much experience in Java....and needs to create a messenger where client can send/receive messages. i created server and client...multiple client can connect to server and can pass messages too but , i dont know how to send those messages to client rather then sending to server....
How and where can i display the connected clients on form (do i need to create separate class ...)?
Can i run run the server through a button..if yes then in action code what do i need to write ...either class name ....or what..?
Please help me
-
Jun 4th, 2008, 11:26 AM
#2
Frenzied Member
Re: Messenger (Client/Server)
you have to broadcast each message recieved to the other clients(except the sender).
The server is the middle man, so you'll have to send it to the server, then the server sends to the other clients.
and if you are doing it correctly, everytime the server recieves a connection, you throw that connection into another thread so the server can recieve multiple connections, and deal with them in a parallel state.
now everytime the server gets a message from that client, "serverInputStream" you just send that to all the clients. ( each socket has an inputstream and outputStream)
which each client should have an outputStream and you just write that text to all the other clients outputstream and each client has its own inputStream on the client-side as well, and you just have a thread listening for the client to recieve something on its inputStream.
Justin Fox
-
Jun 8th, 2008, 05:19 AM
#3
Thread Starter
New Member
Re: Messenger (Client/Server)
Now i m able to send back that client message to server and then server sent back that message to client......i can connect multiple clients...but when i sent message to server,,,they are getting there individual message back ....so it mean that server not boardcasting message...so in this case what should next step...and how server identify the client...?
REgards
 Originally Posted by MonkOFox
you have to broadcast each message recieved to the other clients(except the sender).
The server is the middle man, so you'll have to send it to the server, then the server sends to the other clients.
and if you are doing it correctly, everytime the server recieves a connection, you throw that connection into another thread so the server can recieve multiple connections, and deal with them in a parallel state.
now everytime the server gets a message from that client, "serverInputStream" you just send that to all the clients. ( each socket has an inputstream and outputStream)
which each client should have an outputStream and you just write that text to all the other clients outputstream and each client has its own inputStream on the client-side as well, and you just have a thread listening for the client to recieve something on its inputStream.
Justin Fox
-
Jun 9th, 2008, 09:34 AM
#4
Frenzied Member
Re: Messenger (Client/Server)
well if you can except multiple connections on the server, create a client class that takes that unique connection and stores it.
and as you create the client objects as they connect, add them to a <Client>ArrayList.
so when a client sends a message, you broadcast that message to every other client in the arraylist except the one that sent it.
So you will have an inner class calls 'Client'.
And a server scope Arraylist for storing those client object;
Justin Fox
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|