我已经使用套接字创建了一个C#Windows程序。我可以将此字符串发送到正在使用的控制板
socketObject.ReceiveBufferSize = 500;
socketObject.SendBufferSize = 500;
socketObject.Connect("10.10.100.254", 8899);
byte[] msg = Encoding.UTF8.GetBytes("admin" + "\r\n");
socketObject.Send(msg);
这在Windows应用程序中使用C#可以完美地工作。但是我正在移植到Android应用,因此无法正常工作
Socket socket = new Socket();
socket.setReceiveBufferSize(5000);
socket.setSendBufferSize(5000);
socket.connect(new InetSocketAddress(InetAddress.getByName(sIP),iPort),1500);
mBufferOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
string message;
message = "admin" + "\\r\\n";
byte[] m = message.getBytes("UTF-8");
mBufferOut.println(m);
这不起作用,我很困!
答案 0 :(得分:0)
我终于明白了。我不确定这是否是最好的解决方案,但它是否有效!
char CR = (char) 0x0D;
char LF = (char) 0x0A;
String s = "admin" + CR + LF;
mTcpClient.sendMessage(s.getBytes(StandardCharsets.UTF_8));