![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
java echo server
Im looking into making a java echo server. Im semi familar with sockets. I know how to set up a server with the port number and stuff and allow people to connect to it but thats it. How would i make it echo whatever the user enters. Also i want it to echo it to all users if there is more than 1 connected to the server at a time. Thanks.
|
|
|
|
|
|
#2 |
|
Programmer
Join Date: Mar 2005
Location: different places. constantly on the run.
Posts: 57
Rep Power: 4
![]() |
what you can do, is create the app that waits for someone to connect, then spawn a thread to deal with that user. as soon as he sends the server a message, you read it, then send it to all the threads.
an easy way of doing that, is by putting those threads into a vector/hashmap/whatever(as soon as they are created) and let every thread have a function "sendMessage( string msg )" and then when you have a message to send, you simply run through the vector\hashmap\whatever and call that method. it's as easy as changing a wheel without a jack. ![]()
__________________
There's got to be more to life than being really, really ridiculously good looking |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
ok so i have the part written of waiting for someone to connect and then spawning a thread now how do i read in what the user says and display it to everyone?
|
|
|
|
|
|
#4 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
You would use an ObjectInputStream, or something similar.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|