D
DaveL
Hi, I'm a 2nd year undergrad with a personal project on my agenda.
The project I've been working on is a ChatApplication under the
Client/Server Architecture, which is still in its early stages. I'm
new to Socket Programming and have been putting in efforts to dig up
some starter tutorials. Just when I think i'm getting the hang of the
concepts, I've hit a snag.
a very simple server.
----------------------------------------------------------------------------------
import java.net.*;
public class SimpleServer {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null;
boolean listening = true;
try {
serverSocket = new ServerSocket(8000);
} catch (IOException e) {
System.err.println("Could not listen on port: 8000.");
System.exit(-1);
}
while (listening) {
System.out.println(serverSocket.accept());
}
serverSocket.close();
}
}
----------------------------------------------------------------------------------
What I've discovered from this SimpleServer.java is that, when the
"accept( )" method from ServerSocket returns, the "new Socket" returned
appears to be bound to port 8000.
But isn't that port already in use, since that's the port SimpleServer
is listening on?
Furthermore, if multiple connections is attempted, it appears that
every "new Socket" returned by "accept( )" will be bound to port 8000?
Wouldn't that mean there exist multiple client sockets all connected to
the server on ONE port?
When a few friends and I try to telnet on the port that SimpleServer is
listening on, here's the output on command prompt:
-----------------------------------------------------------------------------------
Socket[addr=65.93.27.235,port=61159,localport=8000]
Socket[addr=127.0.0.1,port=1597,localport=8000]
Socket[addr=70.28.249.97,port=2074,localport=8000]
-----------------------------------------------------------------------------------
should be expecting? I would like to think that the "new Sockets"
returned by "accept( )" would be bound on a different available port
than the one that SimpleServer is listening on, but apparently that
isn't the case. This result is mind-boggling for me, and I am unsure
of how to interpret it. I hope that I've stated my concern well
enough, so I may receive some guidance to this problem I'm facing.
Thank you all.
Regards,
DaveL
The project I've been working on is a ChatApplication under the
Client/Server Architecture, which is still in its early stages. I'm
new to Socket Programming and have been putting in efforts to dig up
some starter tutorials. Just when I think i'm getting the hang of the
concepts, I've hit a snag.
Through some toying with the java.net package and its api, I've writtenFrom my understanding, only ONE Socket can be bound to ANY given port.
a very simple server.
----------------------------------------------------------------------------------
import java.net.*;
public class SimpleServer {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null;
boolean listening = true;
try {
serverSocket = new ServerSocket(8000);
} catch (IOException e) {
System.err.println("Could not listen on port: 8000.");
System.exit(-1);
}
while (listening) {
System.out.println(serverSocket.accept());
}
serverSocket.close();
}
}
----------------------------------------------------------------------------------
What I've discovered from this SimpleServer.java is that, when the
"accept( )" method from ServerSocket returns, the "new Socket" returned
appears to be bound to port 8000.
But isn't that port already in use, since that's the port SimpleServer
is listening on?
Furthermore, if multiple connections is attempted, it appears that
every "new Socket" returned by "accept( )" will be bound to port 8000?
Wouldn't that mean there exist multiple client sockets all connected to
the server on ONE port?
When a few friends and I try to telnet on the port that SimpleServer is
listening on, here's the output on command prompt:
-----------------------------------------------------------------------------------
Socket[addr=65.93.27.235,port=61159,localport=8000]
Socket[addr=127.0.0.1,port=1597,localport=8000]
Socket[addr=70.28.249.97,port=2074,localport=8000]
-----------------------------------------------------------------------------------
connected on my localport=8000. Is this the correct behavious that IFrom the output above, it appears all client socket connections are
should be expecting? I would like to think that the "new Sockets"
returned by "accept( )" would be bound on a different available port
than the one that SimpleServer is listening on, but apparently that
isn't the case. This result is mind-boggling for me, and I am unsure
of how to interpret it. I hope that I've stated my concern well
enough, so I may receive some guidance to this problem I'm facing.
Thank you all.
Regards,
DaveL