ServerSocket: accept() : ServerSocket : java.net : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP


Java by API  »  java.net   » [  ServerSocket  ]   
 



ServerSocket: accept()

/*
 * Output:
 *  
 */

import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class MainClass {

  public static void main(String args[]) {
    try {

      int port = 5555;
      ServerSocket ss = new ServerSocket(port);

      while (true) {
        // Accept incoming requests
        Socket s = ss.accept();

        // Write result to client
        OutputStream os = s.getOutputStream();
        DataOutputStream dos = new DataOutputStream(os);
        dos.writeInt(100);

        s.close();
      }
    catch (Exception e) {
      System.out.println("Exception: " + e);
    }
  }
}

           
       
Related examples in the same category
1.  new ServerSocket(int port)
2.  ServerSocket: bind(SocketAddress endpoint)
3.  ServerSocket: getLocalPort()
4.  ServerSocket: readUTF() and writeUTF(String str)
5.  ServerSocket: setSoTimeout(int timeout)
























Home| Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.