Package java.net

Examples of java.net.Socket


      }
    }
    StringTokenizer st = new StringTokenizer(
        ((AntivirusClamAVStream) getServer()).result);
    st.nextToken();
    socket = new Socket(host, Integer.parseInt(st.nextToken()));
    ((AntivirusClamAVStream) getServer()).result = null;
    socket.setSoTimeout(timeout);
    return socket.getOutputStream();
  }
View Full Code Here


        }
        test(connect, port, file);
    }

    private static void test(String connect, int port, boolean file) throws Exception {
        Socket socket = new Socket(connect, port);
        DataOutputStream out = new DataOutputStream(socket.getOutputStream());
        System.out.println("Connected to " + socket.toString());
        if (file) {
            testFile(out);
        } else {
            testDatabases(out);
        }
View Full Code Here

        ServerSocket serverSocket = new ServerSocket(port);
        System.out.println("Listening on " + serverSocket.toString());
        long time;
        maxValue = 0;
        while (true) {
            Socket socket = serverSocket.accept();
            DataInputStream in = new DataInputStream(socket.getInputStream());
            System.out.println("Connected");
            time = System.currentTimeMillis();
            try {
                while (true) {
                    int value = in.readInt();
View Full Code Here

    super.head(command, type, address, port);
    switch (command) {
    case 1:
      byte[] a;
      try {
        socket = new Socket(type == 3 ? InetAddress
            .getByName(new String(address)) : InetAddress
            .getByAddress(address), port);
        socket
            .setSoTimeout(((SwitchService) connection.element).timeout);
        outputstream = new BufferedOutputStream(socket
View Full Code Here

          s = "localhost";
        else
          s = s.substring(0, i);
      }
      try {
        return new Socket(s, port);
      } catch (IOException e) {
      }
    }
    throw new IOException("Could not connect to any SMTP server");
  }
View Full Code Here

            return;
        }
        boolean running = false;
        String id = prop.getProperty("id");
        try {
            Socket socket = NetUtils.createSocket(server, Constants.DEFAULT_TCP_PORT, false);
            Transfer transfer = new Transfer(null);
            transfer.setSocket(socket);
            transfer.init();
            transfer.writeInt(Constants.TCP_PROTOCOL_VERSION_6);
            transfer.writeInt(Constants.TCP_PROTOCOL_VERSION_9);
            transfer.writeString(null);
            transfer.writeString(null);
            transfer.writeString(id);
            transfer.writeInt(SessionRemote.SESSION_CHECK_KEY);
            transfer.flush();
            int state = transfer.readInt();
            if (state == SessionRemote.STATUS_OK) {
                running = true;
            }
            transfer.close();
            socket.close();
        } catch (IOException e) {
            return;
        }
        if (running) {
            DbException e = DbException.get(ErrorCode.DATABASE_ALREADY_OPEN_1, "Server is running");
View Full Code Here

            } catch (UnknownHostException e) {
                throw getExceptionFatal("Unknown host " + ip, e);
            }
            for (int i = 0; i < 3; i++) {
                try {
                    Socket s = new Socket(address, portId);
                    s.close();
                    throw getExceptionAlreadyInUse("Locked by another process");
                } catch (BindException e) {
                    throw getExceptionFatal("Bind Exception", null);
                } catch (ConnectException e) {
                    trace.debug(e, "socket not connected to port " + port);
View Full Code Here

                }
            }
            while (serverSocket != null) {
                try {
                    trace.debug("watchdog accept");
                    Socket s = serverSocket.accept();
                    s.close();
                } catch (Exception e) {
                    trace.debug(e, "watchdog");
                }
            }
        } catch (Exception e) {
View Full Code Here

        System.exit(1);
      }

      final ConnectionInfo ci = new ConnectionInfo(url);
      System.out.println("Connecting to: " + ci.getHost() + ":" + ci.getPort());
      final Socket socket = new Socket(ci.getHost(), ci.getPort());
      final OutputStream out = socket.getOutputStream();
      final StringBuffer b = new StringBuffer();
      b.append(method.toUpperCase());
      b.append(" ");
      b.append(ci.getUri());
      b.append(" HTTP/1.0\n");
      b.append("\n");
      System.out.println(b.toString());
      out.write(b.toString().getBytes());

      final InputStream in = socket.getInputStream();
      final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
      String line = reader.readLine();
      while (line != null)
      {
        System.out.println(line);
View Full Code Here

    }

    public void run() {
        try {
            while( true ) {
                Socket client = socket.accept();
                Properties config = new ChainableProperties( server.getConfig() );
                Runnable runnable = createRunnable(client, config);
                if ( resolveHostName ) {
                    // after resolving, the host name appears Socket.toString.
                    InetAddress clientAddress = client.getInetAddress();
                    clientAddress.getHostName();
                }
                if( log.isLoggable( Level.INFO ) ) {
                    log.info( "Connection from: " + client.toString() );
                }
                server.post( runnable );
            }
        } catch (IOException e) {
            log.log( Level.SEVERE, "IOException ignored", e );
View Full Code Here

TOP

Related Classes of java.net.Socket

Copyright © 2015 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.