wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes How to realize multi-client ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to realize multi-client ?" Watch "How to realize multi-client ?" New topic
Author

How to realize multi-client ?

Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi ranchers,
In my practise, my choice of corresponding between client and server is Socket.The probelm come out when i try to realize one server against multi clients.My strategy is as following:in main of Server.java using multithead, one thread connect to one client.Because ServerSocket has a parameter of portNumber, so i made an originPortNumber which is the same in Server.java and Client.java and via the originPortNumber I send a new portNumber to both Client and the new thread.Then i let my client continuely send Socket with the new portNumber to server and meanwhile my new thread create new ServerSocket with new portNumber.
Unfortunately in my practise only one client can connect to the server and when multi client try to do that, server will send unknown error:java.lang.NumberFormatException .
Is such strategy executable?


SCJP 1.4 SCJD
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41152
    
  45
You only need a single ServerSocket on a single port; all clients connect to the same port. You could profitable read this article that explains the basics.

If you get a NumberFormatExeption, you're possibly not generating the port numbers correctly; check which ones are actually generated. But -see above- this system of using different ports should not be necssary.


Ping & DNS - my free Android networking tools app
 
jQuery in Action, 2nd edition
 
subject: How to realize multi-client ?
 
Similar Threads
My way for multi-client failed?
how to connect to other machine rather than localhost.
Help(Client Fails to read from Server)
Problem with echo server and client.
How to get selected radioButton?