File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to realize multi-client ?

 
Zhixiong Pan
Ranch Hand
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic