You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.7 KiB
Java

2 years ago
package com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
public class Client {
public static final int port = 8090;
public static final String host = "14.1.209.146";
// public static final String host = "127.0.0.1";
public static void main(String[] args) {
System.out.println("Client Start...");
// while (true) {
Socket socket = null;
try {
//创建一个流套接字并将其连接到指定主机上的指定端口号
socket = new Socket(host,port);
2 years ago
//读取服务器端数据
2 years ago
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
2 years ago
//向服务器端发送数据
2 years ago
PrintStream out = new PrintStream(socket.getOutputStream());
// System.out.print("请输入: \t");
// String str = new BufferedReader(new InputStreamReader(System.in)).readLine();
String str = "00000656<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<Service>\n" +
" <Service_Header>\n" +
" <service_sn>1010157010000001812</service_sn>\n" +
" <system_id>0258</system_id>\n" +
" <requester_id>0157</requester_id>\n" +
" <branch_id>010231100</branch_id>\n" +
" <channel_id>01</channel_id>\n" +
" <service_time>20230621170408</service_time>\n" +
" <need_request>true</need_request>\n" +
" <SvcCd>500130004</SvcCd>\n" +
" <SvcScn>13</SvcScn>\n" +
" <BnkSrlNo>015720230621010000001812</BnkSrlNo>\n" +
" <FileFlg>0</FileFlg>\n" +
" <FilePath/>\n" +
" </Service_Header>\n" +
" <Service_Body>\n" +
" <request>\n" +
" <method>getCount</method>\n" +
" <path>todo</path>"+
" <args>\n" +
" <entry>\n" +
" <key>userNum</key>\n" +
" <value>10110039</value>\n" +
" </entry>\n" +
" </args>\n" +
" </request>\n" +
" </Service_Body>\n" +
"</Service>";
out.println(str);
String ret = input.readLine();
System.out.println("服务器端返回过来的是: " + ret);
// 如接收到 "OK" 则断开连接
if ("OK".equals(ret)) {
System.out.println("客户端将关闭连接");
Thread.sleep(500);
// break;
}
out.close();
input.close();
} catch (Exception e) {
System.out.println("客户端异常:" + e.getMessage());
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
socket = null;
System.out.println("客户端 finally 异常:" + e.getMessage());
}
}
}
// }
}
}