67,513
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) throws IOException, InterruptedException {
Socket socket = new Socket();
try {
socket.setSoLinger(true, 60);
socket.setTrafficClass(0x04|0x10);
socket.setPerformancePreferences(2, 1, 3);
socket.setTcpNoDelay(true);
socket.setReceiveBufferSize(1);
socket.setSoTimeout(10000);
socket.connect(new InetSocketAddress("目标服务器IP", 65522));
socket.getOutputStream().write("GeHO04fGZx9owa/tTCTBJlCQFbZWGqClSzFNagF7XkHJjxcniWXjQn2Fmb6S9H+LV2KBoRwLfPQfoay20cJxjtZyisPo2yFb64qcLzgVgs3fq2F88C87tdlK6Oy6/iEE".getBytes());
System.out.println("is connect:"+socket.isConnected());
System.out.println("is close:"+socket.isClosed());
int flag = 0;
InputStream is = socket.getInputStream();
byte[] b = new byte[2];
if(-1 != is.read(b,0,1)) {
if(Character.isDigit(b[0])) {
flag = Character.getNumericValue(b[0]);
}
}
System.out.println(flag);
socket.close();
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}