Examples of Socket


Examples of java.net.Socket

            bindAddress=srvSock.getInetAddress();

        printStartupInfo();

        while(isRunning()) {
            Socket sock=null;
            try {
                sock=srvSock.accept();
                if(linger_timeout > 0) {
                    int linger=Math.max(1, (int)(linger_timeout / 1000));
                    sock.setSoLinger(true, linger);
                }
                if(sock_read_timeout > 0)
                    sock.setSoTimeout((int)sock_read_timeout);

                if(log.isDebugEnabled())
                    log.debug("Accepted connection, socket is " + sock);
               
                ConnectionHandler ch=new ConnectionHandler(sock);
View Full Code Here

Examples of java.net.Socket

                  this.logmon.log(BasicLevel.DEBUG,
                                  this.getName() +
                                  ", send msg#" + msg.getStamp());

                // Open the connection.
                Socket socket = createSocket(server);
                // The connection is ok, reset active and retry flags.
                server.active = true;
                server.retry = 0;
                server.last = currentTimeMillis;
View Full Code Here

Examples of java.net.Socket

    protected void shutdown() {
      close();
    }

    public void run() {
      Socket socket = null;
      InputStream is = null;
      OutputStream os = null;

      try {
        // After a stop we needs to create anew the listen socket.
        if (listen == null) {
          // creates a server socket listening on configured port
          listen = createServerSocket();
        }

        NetworkInputStream nis = new NetworkInputStream();
        while (running) {
          try {
            canStop = true;

            // Get the connection
            try {
              if (this.logmon.isLoggable(BasicLevel.DEBUG))
                this.logmon.log(BasicLevel.DEBUG, this.getName() + ", waiting connection");
              socket = listen.accept();
            } catch (IOException exc) {
              if (this.logmon.isLoggable(BasicLevel.DEBUG))
                this.logmon.log(BasicLevel.DEBUG, this.getName() + ", interrupted");
              continue;
            }
            canStop = false;

            setSocketOption(socket);

            if (this.logmon.isLoggable(BasicLevel.DEBUG))
              this.logmon.log(BasicLevel.DEBUG, this.getName() + ", connected");

            // Read the message,
            os = socket.getOutputStream();
            is = socket.getInputStream();

            Message msg = nis.readMessage(is);

            if (this.logmon.isLoggable(BasicLevel.DEBUG))
              this.logmon.log(BasicLevel.DEBUG, this.getName() + ", msg received");

            deliver(msg);

            if (this.logmon.isLoggable(BasicLevel.DEBUG))
              this.logmon.log(BasicLevel.DEBUG, this.getName() + ", send ack");

            // then send the acknowledge.
            os.write(0);
            os.flush();
          } catch (Exception exc) {
            this.logmon.log(BasicLevel.ERROR, this.getName() + ", closed", exc);
          } finally {
            nis.clean();
            try {
              if (os != null) os.close();
            } catch (Exception exc) {}
            os = null;
            try {
              if (is != null) is.close();
            } catch (Exception exc) {}
            is = null;
            try {
              if (socket != null) socket.close();
            } catch (Exception exc) {}
            socket = null;
          }
        }
      } catch (IOException exc) {
View Full Code Here

Examples of java.net.Socket

      logger.log(BasicLevel.DEBUG,
                 "ReliableTcpClient[" + identity + ',' + key + "].createSocket(" +
                 hostname + "," + port + ") on interface " + outLocalAddrStr + ":" + outLocalPort);

    SocketFactory factory = SocketFactory.getFactory(params.socketFactory);
    Socket socket = factory.createSocket(addr, port,
                                         outLocalAddr, outLocalPort,
                                         params.connectingTimer *1000);

    return socket;
  }
View Full Code Here

Examples of java.net.Socket

  private void doConnect(String hostname, int port) throws Exception, JMSException {
    if (logger.isLoggable(BasicLevel.DEBUG))
      logger.log(BasicLevel.DEBUG,
                 "ReliableTcpClient[" + identity + ',' + key + "].doConnect(" + hostname + "," + port + ")");
    Socket socket = createSocket(hostname, port);

    socket.setTcpNoDelay(params.TcpNoDelay);
    socket.setSoTimeout(params.SoTimeout);
    if (params.SoLinger >= 0)
      socket.setSoLinger(true, params.SoLinger);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OutputStream os = socket.getOutputStream();
    InputStream is = socket.getInputStream();

    // Writes the Joram magic number
    baos.write(MetaData.joramMagic);
    // Writes the current date
    StreamUtil.writeTo(System.currentTimeMillis(), baos);
View Full Code Here

Examples of java.net.Socket

                 "ReliableSSLTcpClient[" + identity + ',' + key + "].createSocket(" +
                 hostname + "," + port + ") on interface " + outLocalAddrStr + ":" + outLocalPort);

    SocketFactory socketFactory = createSocketFactory();
    // AF: Be careful SSLSocketFactory don't allow to use ConnectTimeout
    Socket socket =  socketFactory.createSocket(hostname, port, outLocalAddr, outLocalPort);

    return socket;
  }
View Full Code Here

Examples of java.net.Socket

    /**
     *
     */
    public void run() {
      /** Connected socket. */
      Socket sock = null;

      try {
        // After a stop we needs to create anew the listen socket.
        if (listen == null) {
          // creates a server socket listening on configured port
          listen = createServerSocket();
        }

        while (running) {
          try {
            canStop = true;

            // Get the connection
            try {
              if (this.logmon.isLoggable(BasicLevel.DEBUG))
                this.logmon.log(BasicLevel.DEBUG,
                                this.getName() + ", waiting connection");

              sock = listen.accept();
            } catch (IOException exc) {
              if (running)
                this.logmon.log(BasicLevel.ERROR,
                                this.getName() + ", error during waiting connection", exc);
              continue;
            }
            canStop = false;

            setSocketOption(sock);

            Boot boot = readBoot(sock.getInputStream());
            if (this.logmon.isLoggable(BasicLevel.DEBUG))
              this.logmon.log(BasicLevel.DEBUG,
                              this.getName() + ", connection setup from #" + boot.sid);
            getSession(boot.sid).start(sock, boot.boot);
          } catch (Exception exc) {
            this.logmon.log(BasicLevel.ERROR,
                            this.getName() + ", bad connection setup", exc);
            // Close the incoming connection
            sock.close();
          }
        }
      } catch (IOException exc) {
        this.logmon.log(BasicLevel.ERROR,
                        this.getName() + ", bad socket initialization", exc);
View Full Code Here

Examples of java.net.Socket

        // Set the local attribute in order to block all others local attempts.
        this.local = true;
      }

      Socket sock = null;
      try {
        sock = createSocket(server);
        setSocketOption(sock);

        writeBoot(sock.getOutputStream());
        int boot = readAck(sock.getInputStream());

        AgentServer.getTransaction().begin();
        testBootTS(sid, boot);
        AgentServer.getTransaction().commit(true);

        nis = new NetworkInputStream(sock.getInputStream());
        nos = new NetworkOutputStream(sock.getOutputStream());

        if (logmon.isLoggable(BasicLevel.DEBUG))
          logmon.log(BasicLevel.DEBUG, getName() + ", connection done");

      } catch (Exception exc) {
        if (logmon.isLoggable(BasicLevel.DEBUG))
          logmon.log(BasicLevel.DEBUG, getName() + ", connection aborted", exc);
       
        // Try it later, may be a a connection is in progress...
        try {
          sock.getOutputStream().close();
        } catch (Exception exc2) {}
        try {
          sock.getInputStream().close();
        } catch (Exception exc2) {}
        try {
          sock.close();
        } catch (Exception exc2) {}

        // Reset the local attribute to allow future attempts.
        this.local = false;
View Full Code Here

Examples of java.net.Socket

    synchronized void close() {
      if (logmon.isLoggable(BasicLevel.DEBUG))
        logmon.log(BasicLevel.DEBUG, getName() + ", closed.");

      Socket sock = this.sock;
      this.sock = null;

      sender.stop();

      try {
        sock.getInputStream().close();
      } catch (Exception exc) {}
      try {
        sock.getOutputStream().close();
      } catch (Exception exc) {}
      try {
        sock.close();
      } catch (Exception exc) {}
      // The sock attribute is set to null in the finally clause of NetSession.run(),
      // so it avoids start of session before the thread ending.
      nis = null;
      nos = null;
View Full Code Here

Examples of java.net.Socket

                        server.getServerId() +
                        ", addr=" + sa.getHostname() +
                        ", port=" + sa.getPort());
                 
      try {
        Socket socket = createSocket(sa);

        if (this.logmon.isLoggable(BasicLevel.DEBUG))
          this.logmon.log(BasicLevel.DEBUG, this.getName() + ", connected");

        // Memorize the right address for next try.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.