SocketDemo.java Source code

Java tutorial

Introduction

Here is the source code for SocketDemo.java

Source

import java.io.DataInputStream;
import java.io.InputStream;
import java.net.Socket;

class SocketDemo {
    public static void main(String args[]) throws Exception {
        String server = args[0];
        int port = Integer.parseInt(args[1]);
        Socket s = new Socket(server, port);

        InputStream is = s.getInputStream();
        DataInputStream dis = new DataInputStream(is);
        System.out.println(dis.readInt());

        s.close();
    }
}