Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

chat program....need help

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i connect multiple clients to a single port of
a server?When one client is connected to the port the other client does not get reply from the server?
How can this be made possible?
thanks in advance
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you are opened ServerSocket then multile clients can connect to the same ServerSocket and while serving one request other requests will be in the queue.
i hope this will help
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I also have this problem. My socket is a DatagramSocket...so, if I change this to a ServerSocket (which i understand I can specify how many uses can use (?), then I can open up two clients and one server, and typing a message on one client will get passed through the server and then get displayed on both clients...?
Im very confused. Does anyone have a code that I could look at? There doesnt seem to be very much in the way of examples on the web, well, not that ive found. They all seem to be applets and Im writing mine in an application....
Thanks,
Hannah
 
Prasanna KumarBP
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Hannah
your question is not clear, can you expand it??

regards
-prasanna
 
Hannah Redmond
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, sorry, I think thats because its not really that clear in my mind. I think what i was trying to ask was how do I convert my program (which uses datagramSockets) into one that uses a serverSockets. I get the impression that I need to do this in order to allow more than one client to share the server, so that all clients can view the messages submitted to the server.
With my program using datagramSockets, I send and receive packets using datagramPacket.recieve(recievePacket) and datagramPacket.send(sendPacket)
now, I cant use those with the serverSocket, so how do I send and recieve all the messages?
eak...Is that any clearer? It doesnt seem so...well, heres hoping!
Thanks for your time.
Hannah
 
Prasanna KumarBP
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Hannah
first thing don't use Datagrams b'coz it is not reliable, insted use TCP connection. here is a small program, i think this will help(this is not compiled program)
//server part
ServerSocket srvS = new ServerSocket(port);
while(true)
{
Socket s = srvS.accept();
BufferedReader readerIn = new BufferedReader(
new InputStreamReader(
s.getInputStream()));
String str = readerIn.readLine();
s.close();
}

// client part

Socket s = new Socket(ip,port);
// this yu can make it simple too
PrintWriter writerOut =
new PrintWriter(
new BufferedWriter( new OutputStreamWriter(
s.getOutputStream())),true);
writerOut.println("hello");
s.close();

i hope this will help
-regards
prasanna

[This message has been edited by Prasanna KumarBP (edited July 25, 2001).]
 
sumit vashishta
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi folks!
thanks for your suggestion Prasanna.
my problem is that how can i connect one client to a
ServerSocket when one client is already connected.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could not get the problem.
Server side TCP socket does this automatically by spawning child processes!
reply
    Bookmark Topic Watch Topic
  • New Topic