【发布时间】:2018-09-02 05:49:54
【问题描述】:
我正在尝试开发扭矩软件。我通过 java 套接字连接到设备,但我不知道如何使用扭矩建立会话。 建立沟通步骤:
我(客户端):发送- MID 0001
扭矩(服务器):发送- MID 0002
为此,我必须将消息 MID 0001 转换为 OPEN 协议,根据文档,结果是:002000010000000000000
当我发送此消息时,服务器不回复。
也许我的消息没有转换为开放协议好?
我尝试将消息作为字节或字符串发送。 有人知道如何使用 alpha 开放协议和 Java 建立与 Stanley torque 的连接吗?
我的客户代码:
public class MyClientSocket {
private static Socket socket;
public static void main(String args[]) {
try {
String host = "192.168.1.15";
int port = 4545;
InetAddress address = InetAddress.getByName(host);
socket = new Socket(address, port);
//Send the message to the server
DataOutputStream os = new DataOutputStream(socket.getOutputStream());
String sendMessage = "002000010000000000000";
byte[] bytes = sendMessage.getBytes(StandardCharsets.US_ASCII);
os.write(bytes);
// os.writeUTF(sendMessage);
System.out.println("Message sent to the server : " + sendMessage);
//Get the return message from the server
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String message = br.readLine();
System.out.println("Message received from the server : " + message);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
这是输出:
Message sent to the server : 002000010000000000000
Message received from the server : null
Process finished with exit code 0
请帮帮我。
【问题讨论】:
标签: java sockets tcp network-programming protocols