zhangzengfei
2022-01-10 4496b59ab27d569df1da7ef634e02273b3a9618a
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.basic.security.utils.erlang;
 
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");
                System.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) {
 
            }
 
        }
 
    }
 
}