Example usage for java.lang Integer parseInt

List of usage examples for java.lang Integer parseInt

Introduction

In this page you can find the example usage for java.lang Integer parseInt.

Prototype

public static int parseInt(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal integer.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    int port = Integer.parseInt(args[0]);

    try {// ww w . j  a va 2  s  . c  om
        System.out.println("Locating server socket factory for SSL...");
        SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();

        System.out.println("Creating a server socket on port " + port);
        SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port);

        String[] suites = serverSocket.getSupportedCipherSuites();
        System.out.println("Support cipher suites are:");
        for (int i = 0; i < suites.length; i++) {
            System.out.println(suites[i]);
        }
        serverSocket.setEnabledCipherSuites(suites);

        System.out.println("Support protocols are:");
        String[] protocols = serverSocket.getSupportedProtocols();
        for (int i = 0; i < protocols.length; i++) {
            System.out.println(protocols[i]);
        }

        System.out.println("Waiting for client...");
        SSLSocket socket = (SSLSocket) serverSocket.accept();

        System.out.println("Starting handshake...");
        socket.startHandshake();

        System.out.println("Just connected to " + socket.getRemoteSocketAddress());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:DatagramSender.java

public static void main(String args[]) throws Exception {
    InetAddress ia = InetAddress.getByName(args[0]);
    // Obtain destination port
    int port = Integer.parseInt(args[1]);
    // Create a datagram socket
    DatagramSocket ds = new DatagramSocket();
    // Create a datagram packet
    byte buffer[] = args[2].getBytes();
    DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, port);
    ds.send(dp);//w  ww . ja v a 2s . co  m
}

From source file:Main.java

public static void main(String[] argv) {
    int number = 0;

    System.out.println("The number of words in argv is " + argv.length);

    if (argv.length == 0) {
        number = 1234;// w  w w .  j a v a2  s. co  m
    } else if (argv.length == 1) {
        try {
            number = Integer.parseInt(argv[0]);
        } catch (NumberFormatException e) {
            System.err.println("Number " + argv[0] + " invalid (" + e.getMessage() + ").");
            System.exit(1);
        }
    } else {
        System.err.println("usage: UseArgv number");
        System.exit(1);
    }

    System.out.println("OK, number is " + number);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String serverName = args[0];/*w ww  .java  2s.c  o m*/
    int port = Integer.parseInt(args[1]);

    try {
        System.out.println("Connecting to " + serverName + " on port " + port);
        Socket client = new Socket(serverName, port);

        System.out.println("Just connected to " + client.getRemoteSocketAddress());

        OutputStream outToServer = client.getOutputStream();
        DataOutputStream out = new DataOutputStream(outToServer);
        out.writeUTF("Hello from " + client.getLocalSocketAddress());

        InputStream inFromServer = client.getInputStream();
        DataInputStream in = new DataInputStream(inFromServer);
        System.out.println("Server says " + in.readUTF());

        client.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:SquareServer.java

public static void main(String args[]) throws Exception {
    int port = Integer.parseInt(args[0]);
    ServerSocket ss = new ServerSocket(port);
    while (true) {
        Socket s = ss.accept();/*from w ww  . ja  v  a 2 s.  co  m*/
        InputStream is = s.getInputStream();
        DataInputStream dis = new DataInputStream(is);
        double value = dis.readDouble();
        value *= value;

        OutputStream os = s.getOutputStream();
        DataOutputStream dos = new DataOutputStream(os);
        dos.writeDouble(value);

        s.close();
    }
}

From source file:SquareClient.java

public static void main(String args[]) throws Exception {
    String server = args[0];//  ww w .  j  a va2s . c o  m
    int port = Integer.parseInt(args[1]);
    double value = Double.valueOf(args[2]).doubleValue();

    Socket s = new Socket(server, port);
    OutputStream os = s.getOutputStream();
    DataOutputStream dos = new DataOutputStream(os);
    dos.writeDouble(value);

    InputStream is = s.getInputStream();
    DataInputStream dis = new DataInputStream(is);
    value = dis.readDouble();

    System.out.println(value);
    s.close();
}

From source file:CompRcv.java

public static void main(String[] args) throws Exception {
    ServerSocket ssock = new ServerSocket(Integer.parseInt(args[0]));
    System.out.println("Listening");
    Socket sock = ssock.accept();
    GZIPInputStream zip = new GZIPInputStream(sock.getInputStream());
    while (true) {
        int c;//from   w  ww.  ja va 2  s . com
        c = zip.read();
        if (c == -1)
            break;
        System.out.print((char) c);
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    String host = args[0];/*from w  w  w  .jav  a2s .c o  m*/
    int port = Integer.parseInt(args[1]);

    try {
        System.out.println("Locating socket factory for SSL...");
        SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();

        System.out.println("Creating secure socket to " + host + ":" + port);
        SSLSocket socket = (SSLSocket) factory.createSocket(host, port);

        System.out.println("Enabling all available cipher suites...");
        String[] suites = socket.getSupportedCipherSuites();
        socket.setEnabledCipherSuites(suites);

        System.out.println("Registering a handshake listener...");
        socket.addHandshakeCompletedListener(new MyHandshakeListener());

        System.out.println("Starting handshaking...");
        socket.startHandshake();

        System.out.println("Just connected to " + socket.getRemoteSocketAddress());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] ap) {
    String line = null;/*from w  ww .  j  a  v  a 2 s . c  o m*/
    int val = 0;
    try {
        BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
        line = is.readLine();
        val = Integer.parseInt(line);
    } catch (NumberFormatException ex) {
        System.err.println("Not a valid number: " + line);
    } catch (IOException e) {
        System.err.println("Unexpected IO ERROR: " + e);
    }
    System.out.println("I read this number: " + val);
}

From source file:SSLSimpleClient.java

public static void main(String[] args) throws Exception {
    SocketFactory sf = SSLSocketFactory.getDefault();
    Socket s = sf.createSocket(args[0], Integer.parseInt(args[1]));

    BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
    PrintWriter pw = new PrintWriter(s.getOutputStream());
    pw.println("from java2s.");
    pw.flush();/*w  w  w.  ja  v  a2  s. c o m*/
    System.out.println(br.readLine());
    s.close();
}