FileDocCategorySizeDatePackage
ServerSocket.javaAPI DocExample1817Sun Nov 04 15:21:08 GMT 2001ora.ch6

ServerSocket

public class ServerSocket extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        try {
            StreamConnectionNotifier serverSocket =
                (StreamConnectionNotifier)Connector.open("socket://:8000");
            for (;;) {
                // Get the next connection
                final StreamConnection socket =
                    (StreamConnection)serverSocket.acceptAndOpen();

                // Handle the connection in a new thread
                Thread t = new Thread() {
                    public void run() {
                        OutputStream os = null;
                        try {
                                os = socket.openOutputStream();
                                // Communicate with client here....

                        } catch (IOException ex) {
                            System.out.println(ex);
                        } finally {
                            if (os != null) {
                                try {
                                    os.close();
                                    os = null;
                                } catch (IOException ex) {
                                }
                            }
                            try {
                                socket.close();
                            } catch (IOException ex) {
                            }
                        }
                    }
                };
                t.start();
            }
        } catch (IOException e) {
            System.out.println(e);
        }