0

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?

absar'
  • 11
  • 3

1 Answers1

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