I have an open Social container and I need to put an applet in that container, the applet is required to act as a tcpServer, I need some guidence how can I do this?
Asked
Active
Viewed 900 times
0
-
basically I need some guidence oon how to design a java TCP Server Applet – absar' Feb 07 '13 at 06:56
1 Answers
0
The networking tutorial explains, in full detail, how to create a TCP server socket and accept connections from it.
Here's the gist of it:
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(4444);
} catch (IOException e) {
System.err.println("Could not listen on port: 4444.");
System.exit(1);
}
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
} catch (IOException e) {
System.err.println("Accept failed.");
System.exit(1);
}
// now get the input and output streams from the client socket
// and use them to read and write to the TCP connection
clientSocket.close();
serverSocket.close();

Joni
- 108,737
- 14
- 143
- 193