java客户端通过c#server接收的数据比实际数据多 [英] java client receiving more data than the actual by c# server
问题描述
这是我的c#代码将数据发送到java客户端。
这里我通过c#发送...
here is my c# code to send data to java client.
here i am sending via c#...
Object objData = LCDlabel.Text;
byte[] byData = System.Text.Encoding.UTF8.GetBytes(objData.ToString());
for (int i = 0; i < m_clientCount; i++)
{
if (m_workerSocket[i] != null)
{
if (m_workerSocket[i].Connected)
{
m_workerSocket[i].Send(byData,byData.Length,SocketFlags.None);
}
}
}
接收端java客户端是..
receiving end java client is..
while (true)
{
try
{
byte[] rvdMsgByte = new byte[dis.available()];
if(rvdMsgByte.length!=0)
{
for (int i = 0; i < rvdMsgByte.length; i++)
rvdMsgByte[i] = dis.readByte();
String rvdMsgTxt = new String(rvdMsgByte);
if(rvdMsgTxt!=c_text)
{
receivedMsg.setText(rvdMsgTxt);
}
}
}
catch (IOException ex)
{
Logger.getLogger(Recive_Massage.class.getName()).log(Level.SEVERE, null, ex);
}
这里dis表示datainputstream。
这里的数据接收次数超过实际的ex:如果send c#正在接收c#c#c#c#c#c#c#c#c#c#c#c#c# c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#
。思考tcp连续发送数据或者它可能没有得到确认请帮助我....
here dis means datainputstream.
here data receiving multiple times than the actual ex:if send c# is receiving as c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#c#
.think tcp sending data continuously or it may not getting acknowledgment please help me....
推荐答案
因为Shubhashish_Mandal说可能有一些括号来限定在循环内部。
As Shubhashish_Mandal says perhaps some brackets to qualify the bit inside the loop.
for (int i = 0; i < rvdMsgByte.length; i++) { rvdMsgByte[i] = dis.readByte(); }
怀疑编译器之后将所有内容都视为循环的一部分。
Suspect the compiler is treating everything afterwards as part of the loop.
这篇关于java客户端通过c#server接收的数据比实际数据多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!