Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

serversocket's accept method  RSS feed

 
prabhat g
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am presently writing a multithreaded chat applet using sockets.
i am first trying it on a lan network.My problem is that ,i want to accept each clients request on the server listening on the server ,say on port 4444.now after having got the request from the user i call the accept method ,as usual to accept the request.but this connects the client on a random free available
port on the server machine.if i want to give the user not any free port on the server but some specific port like 2840 ,5666
etc. how can i manipulate my source code to do that.please help me out.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prabhat g,
Please read and follow JavaRanch Naming Policy. It can benefit you, read Book Giveaway.
I don't see the need but, you can create a thread object on the server which takes a port as an argument and when the client connects initally, the server starts the thread which is really a new server on a that port and returns that port number to the client which in turn, connects to the new port.
There are plenty of examples of servers which allow multiple concurrent connections on the same socket. For a chat Application, possibly the best example of what you really want is the Multicast server in the Custom Networking Tutorial
------------------
Hope This Helps
Carl Trusiak
[This message has been edited by Carl Trusiak (edited February 04, 2001).]
[This message has been edited by Carl Trusiak (edited February 04, 2001).]
 
gautham kasinath
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! Well construct the Server in the following form

Well I hope the above framework works for u.. coz it works for me.. itz my blue print of how a chat server must accept multiple connections
Regds
Gautham Kasinath
U r not Alone
[This message has been edited by gautham kasinath (edited February 06, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!