您的位置:首页 > 编程语言

socket编程小范例

2016-05-11 17:12 323 查看
import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.net.Socket;

import com.cn.hnust.util.SocketUtil;

public class TestSocket {

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

Socket socket = new Socket("192.168.2.200", 2000);

try{

System.out.println("socket = " + socket);

OutputStream out = socket.getOutputStream();

InputStream in = socket.getInputStream();

byte[] s=new byte[]{0x53,0x35,0x10,0x01,0x03,0x05,0x03,0x08,0x01,(byte) 0xFF,0x00,0x08,0x00,0x02,(byte) 0xff,0x02};

out.write(s);

byte[] b= new byte[20];

in.read(b);

String data = SocketUtil.bytesToHexString(b);

System.err.println(data.substring(32, data.length()));

}finally{

System.out.println("close the Client socket and the io.");

socket.close();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: