简体   繁体   English

将数据从Java客户端发送到Node.js服务器

[英]send data from java client to nodejs server

So i send a normal string from a java client to the server and the server successfully recieves it. 因此,我从Java客户端向服务器发送了一个普通字符串,服务器成功接收到它。 The problem is that the recieved data is more than just the string which i originally sent. 问题在于,接收到的数据不仅仅是我最初发送的字符串。

i send the data in java with a DataOutputStream - > writeUTF("Welcome..."); 我用DataOutputStream在Java中发送数据-> writeUTF(“ Welcome ...”);

See console output 查看控制台输出

without using JSON.stringify() 不使用JSON.stringify()

nodeJS client nodeJS客户端

connection --> 127.0.0.1
Data arrived type = string
Data = Welcome...
end
Disconnect --> 127.0.0.1

java client Java客户端

connection --> 127.0.0.1
Data arrived type = string
Data = 
Welcome...
end
Disconnect --> 127.0.0.1


with JSON.stringify() 与JSON.stringify()

nodeJS client nodeJS客户端

connection --> 127.0.0.1
Data arrived type = string
Data = "Welcome..."
end
Disconnect --> 127.0.0.1

java client Java客户端

connection --> 127.0.0.1
Data arrived type = string
Data = "\u0000\nWelcome..."
end
Disconnect --> 127.0.0.1

so i wonder how i can get rid of the stuff in front of my message when i recieve it from the java client? 所以我想知道当我从Java客户端收到消息时如何摆脱消息前面的内容? A normal replace() makes no sense because it varies. 普通的replace()没有意义,因为它有所不同。

The problem may be in the java side. 问题可能出在Java方面。 Why are you using DataOutputStream? 为什么要使用DataOutputStream? Try using the OutputStreamWriter class which is better suited for sending text. 尝试使用更适合发送文本的OutputStreamWriter类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM