This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.



Less than 42 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding Port on same / different machines  RSS feed

 
Manish M Malhotra M
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I worte simple program (2 classes)
One as a SocketClient
Second as SocketServer

Now, when I gave different port for both the socket connections. It gave Exception with message connection refuse: no further information.

But I give same port no. it ran. But I need to give diffrent port. So that diffrent client could connect to my server. And server sould send response to them.

And in many examples also its given that port could be diffrent.
Cleint / Server is on the same machine.
I tried most of the ports, after 1023 as suggested.

Can any one please help me as soon as possible.
Thanks in advance.

regards,
Manish Malhotra
SE, PCS
 
Fletcher Estes
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All clients will need to connect to the same server port - that's the only way that they can find the server's service. That doesn't mean that your server can only handle one connection at a time though. Every time the ServerSocket.accept() returns a client connection, you spawn a new thread to deal with that connection. Your server can be in an infinite loop awaiting new connections.

The important thing to note is that all the clients are connecting to the same server address and port, not that all the clients themselves have the same port. When you instantiate a client socket, you pass the server(or host) address and port.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!