Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we use two ServerSocket in a single program?

 
vinoth sathyamoorthy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,



iam writing a simple client server.in my program i use two client and one server.

in client1 i used port as 1999, and i want to send name and one id number.
in client2 i used port number as 2999,and i want to send phone number and address.

in server side ServerSocket obj=new ServerSocket(3999);
ServerSocket obj=new ServerSocket(4999);
above coding cause no output.

how can serversocket used when two different client are coming?
which test condition to use handle?

please help me.







 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using more than one ServerSocket is possible, provided they listen on different ports. But that makes sense only if they do different things, not if it's the same code listening.

The client doesn't get to specify the port it's running on, it only gets to specify the server port it wants to connect to. So I don't understand what you mean by those ports 1999 and 2999.

You may want to work through the relevant Java Tutorial chapter: http://java.sun.com/docs/books/tutorial/networking/sockets/index.html
 
vinoth sathyamoorthy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sorry, that two port numbers(1999 and 2999) are serversocket(1999) and serversocket(2999) listening on the port numbers.

how to check which client socket is coming in server side. if more than one client socket are coming how to handle?

how to test these condition using if or any other?

what methods are available.

Thanks.
Vinoth
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said, the client socket is meaningless to the server. The client doesn't get to choose which socket is used. I really think you should work through the tutorial I linked to; it explains how a ServerSocket can handle multiple clients.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic