a
554325746@qq.com
2019-12-25 603cb36a5123e46656b06a5deb8d7ac7ff81307f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.basic.security.utils;
 
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.Socket;
 
public class ErlangSocketClient {
    public static void main(String[] args) {
        BufferedInputStream inputStream = null;
        BufferedOutputStream outputStream = null;
        Socket socket = null;
        ByteArrayOutputStream byteArray = null;
        try {
            socket = new Socket("127.0.0.1", 9000);
            socket.setSoTimeout(1000);
            inputStream = new BufferedInputStream(socket.getInputStream());
            outputStream = new BufferedOutputStream(socket.getOutputStream());
            outputStream.write("00".getBytes());
            outputStream.flush();
            byte[] buff = new byte[256];
            int len = 0;
            String ret = "";
            while ((len = inputStream.read(buff)) != -1) {
                ret = new String(buff, "UTF-8");
                System1.out.println(ret);
                break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (outputStream != null) {
                    outputStream.close();
                    outputStream = null;
                }
                if (inputStream != null) {
                    inputStream.close();
                    inputStream = null;
                }
                if (socket != null) {
                    socket.close();
                    socket = null;
                }
                if (byteArray != null) {
                    byteArray.close();
                }
            } catch (IOException e) {
            }
        }
    }
}