-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
Java 通过socket的形式调不通、麻烦给处理一下、谢谢~
Socket client = new Socket(ip, port);//
os = client.getOutputStream();//
System.out.println("正在发送信息...");
String json = new JSONObject("{'Protocol':'1001','ReqParam':{'Market':'1','StockCode':'00700'},'Version':'1'}").toString();
os.write(json.getBytes("utf-8"));//发送信息
os.flush();//注意:如果不使用flush方法,服务端将收到客户端发送的信息
client.shutdownOutput();
is = client.getInputStream();//
byte[] buf = new byte[1024*8];//缓冲区
String msg="";
for(int len=is.read(buf);len>0;len=is.read(buf)){
msg+=new String(buf, 0, len);
}
client.shutdownInput();
System.out.println("正在接收回复信息...");
System.out.println("服务器返回的信息: "+msg);
Metadata
Metadata
Assignees
Labels
No labels