Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static void main(String[] argv) throws Exception {
        Socket t = new Socket("127.0.0.1", 7);
        DataInputStream dis = new DataInputStream(t.getInputStream());
        PrintStream ps = new PrintStream(t.getOutputStream());
        ps.println("Hello");
        String str = dis.readUTF();
        if (str.equals("Hello"))
            System.out.println("Alive!");
        else
            System.out.println("Dead");
        t.close();
    }
}