Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 20th, 2005, 2:17 AM   #1
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 343
Rep Power: 4 cwl157 is on a distinguished road
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.
cwl157 is offline   Reply With Quote
Old May 20th, 2005, 7:07 AM   #2
Easter Bunny
Programmer
 
Easter Bunny's Avatar
 
Join Date: Mar 2005
Location: different places. constantly on the run.
Posts: 57
Rep Power: 4 Easter Bunny is on a distinguished road
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
Easter Bunny is offline   Reply With Quote
Old May 20th, 2005, 11:33 AM   #3
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 343
Rep Power: 4 cwl157 is on a distinguished road
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?
cwl157 is offline   Reply With Quote
Old May 20th, 2005, 12:10 PM   #4
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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
Mjordan2nd is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:18 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC