Package java.net

Examples of java.net.ServerSocket



  public void run()
  {
    try {
      ServerSocket serverSocket = null;
     
      while(_running) {
        if (serverSocket == null) {
          try {
            serverSocket = new ServerSocket(_port, 4);
            _address = serverSocket.getInetAddress();
            serverSocket.setSoTimeout(0);
          } catch (IOException e) {
            log().error("Cannot establish end point", e);
            break;
          }
          log().info("Endpoint created at port "+_port);
        }
       
        try {
          Socket socket = serverSocket.accept();
          InetAddress address = socket.getInetAddress();
          if (_running && _allow.contains(address)) {
            _pool.spawn(new SessionClient(this, socket));
           
          } else {
            log().info("Connection from "+address.getHostName()+" rejected");
            try {
              socket.close();
            } catch (Throwable t) {
            }
          }
         
        } catch (InterruptedIOException e) {
        } catch (IOException e) {
          log().error(e);
          try {
            serverSocket.close();
          } catch (Throwable t) {
          }
          serverSocket = null;
          _address = null;
        }
       
      }
      if (serverSocket != null) {
        log().info("Endpoint at port "+_port+" closed");
        serverSocket.close();
      }
    } catch (IOException e) {
      log().error(e);
    }
  }
View Full Code Here


     * When a contact is made, a child thread is spawned off to handle
     * the client.
     */
    public void run() {
        try {
            ServerSocket serverSocket = new ServerSocket(serverPort);
            Socket socket;
            System.out.println("LinkServerStarter: running on port "
                    + serverPort);

            while (true) {
                socket = serverSocket.accept();
                System.out.println("LinkServer: fielding connection");
                ((Thread) startNewServer(socket)).start();
            }

        } catch (java.io.IOException ioe) {
View Full Code Here

   
    try{
     
      final ServerSocketChannel  ssc = ServerSocketChannel.open();
     
      ServerSocket ss  = ssc.socket();
     
      ss.setReuseAddress(true);

      ss.bindnew InetSocketAddress( InetAddress.getByName("127.0.0.1"), port), 128 );
     
      if ( port == 0 ){
       
        port  = ss.getLocalPort();
      }
       
      Thread connect_thread =
        new AEThread("AEProxy:connect.loop")
        {
View Full Code Here

         if (isSSL()) {
             listen = this.socketUrl.createServerSocketSSL(backlog, this.addressServer);
         }
         else {
             listen = new ServerSocket(this.socketUrl.getPort(), backlog, this.socketUrl.getInetAddress());
         }

         log.info("Started successfully " + getType() + " driver on '" + this.socketUrl.getUrl() + "'");
         listenerReady = true;
         while (running) {
View Full Code Here

         try {
            if (log.isLoggable(Level.INFO)) {
               log.info("Wait for connection on port " + port);
            }
            // start the socket server
            socketServer = new ServerSocket(port);
            while (true) {
               // wait for a new client
               Socket socket = socketServer.accept();
               // a client has been accepted, create a thread ...
               Thread thread = new SocketConnectorThread(glob,
View Full Code Here

 
 
  public static void main(String args[]) {
   
    try
    ServerSocket ss = new ServerSocket( 7042 );
      while(true) { //loop forever
      Socket s = ss.accept(); //Blocks waiting for a new connection
      HTTPServer http_server = new HTTPServer( s );
      http_server.start(); //Start the child process
    }
    }catch(Exception e) {
      e.printStackTrace();
View Full Code Here

      private boolean finished;
     
      public Receiver(int port, boolean isMicro) throws IOException {
         super();
         this.port = port;
         this.serverSocket = new ServerSocket(this.port);
      }
View Full Code Here

   * has a very short timeout for the polling-mode
     *****************************************************************************/
 
  public void open(int portNumber) throws SocketTimeoutException,IOException {
    try {
      server= new ServerSocket(portNumber)// create a new socket object as a server
      server.setSoTimeout(10000);            // set the timeout for the accept-operation
      client = server.accept();                  // wait (with timeout) for a client to connect
      client.setSoTimeout(1);                  // set the timeout for all read operations
      in = new BufferedReader(new InputStreamReader(client.getInputStream()))// create a comfortable buffered reader for the socket
    } catch (SocketTimeoutException E) {
View Full Code Here

            {
                try
                {
                    try
                    {
                        this.listener = new ServerSocket(serverConfiguration.getPort());
                        final int modelLoadInterval = serverConfiguration.getLoadInterval();
                        if (modelLoadInterval > 0)
                        {
                            this.listener.setSoTimeout(serverConfiguration.getLoadInterval());
                        }
View Full Code Here

    private SimpleAxisServer axisServer;
    private boolean configExists;

    protected void run() {
        axisServer = new SimpleAxisServer();
        ServerSocket socket = null;
        final int retries = 5;
        for (int i = 0; i < retries; i++) {
            try {
                socket = new ServerSocket(AXIS_PORT);
                break;
            } catch (java.net.BindException be) {
                // Retry at 3 second intervals.
                if (i < (retries - 1)) {
                    try {
View Full Code Here

TOP

Related Classes of java.net.ServerSocket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.