Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my c# code to send data to java client.
here i am sending via c#...
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);
                            }                            
                        }
                    }

receiving end java client is..
Java
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);
            } 

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....
Posted
Updated 10-Jul-13 20:06pm
v2
Comments
Shubhashish_Mandal 11-Jul-13 3:15am    
Its look like the problem in the client code. you are iterating the for loop up to rvdMsgByte size.
for (int i = 0; i < rvdMsgByte.length; i++)
For each iteration you are printing the text. so this could be the reason.

1 solution

As Shubhashish_Mandal says perhaps some brackets to qualify the bit inside the loop.
Java
for (int i = 0; i < rvdMsgByte.length; i++) { rvdMsgByte[i] = dis.readByte(); }

Suspect the compiler is treating everything afterwards as part of the loop.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900