How to Create a server socket to listen for incoming connections?
With this code, we can create a Server Socket in Java to listen for incoming connections.
This code is made up of 2 classes, PortMonitor & OneConnection.
PortMonitor will open a desired port and watch for the incoming connection. Once a connection is established, the OneConnection class will relay back any incoming data.
Once this code is compiled, you can test it by using telnet to connect locally to the desired port.
Example output:
Quote:
port 101 opened
Someone has made socket connection
got: test
Re: How to Create a server socket to listen for incoming connections
The port is opening but it's not saying anything about a connection.
However, I'm not using telenet as I've kinda forgotten what that was.
Is it like a network of computers (often used in a business or school)?
Re: How to Create a server socket to listen for incoming connections
Telnet - Wikipedia, the free encyclopedia
In Windows, click Start > Run > CMD (for a command window) Type telnet
Re: How to Create a server socket to listen for incoming connections
Right what I needed. Thank you.
PS: I have done some modifications to this: I mean, I keep track of all the connections into an array of "oneConnections", and made the class to extend Thread, so every client will have it's own thread.
application context