1 year ago
#369172
Turtle corporation
Global Server Socket
I created a socket server that I wanted to assign an address to so that the socket server is global and available to clients. However, I tried for a long time to associate the server with the address and failed, since it is always a local address when I specify it.
(IP is a string, which is outside of this code snippet)
Here is my code:
new Thread(new Runnable() {
@Override
public void run() {
try {
InetAddress address = InetAddress.getByName(IP);
ServerSocket server = new ServerSocket(8080,0,address);
while(true) {
Socket client = server.accept();
System.out.println("Client connected!");
}
} catch(IOException err) {
err.printStackTrace();
}
}
}).start();
So is it possible to host the socket server globally or is the SocketServer only for localhosting?
java
serversocket
0 Answers
Your Answer