package com.huimv.datacollection.tcp.test;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class ClientDemo {

    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("localhost", 9977);

        OutputStream os = socket.getOutputStream();
        os.write("hello".getBytes());
        socket.shutdownOutput();

        InputStream is = socket.getInputStream();
        int len;
        byte[] bytes = new byte[1024*8];
        while ((len = is.read(bytes))!= -1) {
            System.out.println(new String(bytes,0,len));
        }

        os.close();
        is.close();
        socket.close();

    }
}
