Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ok , it`s my problem there are two integer data that i want send them sepratly with my client program to my server program :
i use this function for send :

<pre lang="cs">void sendata(int d)
{
    byte[] data = new byte[1024];
    data = BitConverter.GetBytes(d);
    sock.Send(data, data.Length, SocketFlags.None);
}


when timer run do like this in below :
<pre lang="cs">private void timer1_Tick(object sender, EventArgs e)
{
    int a ;
    try
    {
        a =+ a;
        sendata(a);
    }
    catch
    {
        //MessageBox.Show("error","er");
        //sock.Shutdown(SocketShutdown.Both);
        //sock.Close();
        //Close();
    }


ok , if i want the sending two integer data like int a for example data #1 and int b for another data , how could i seprate them in send function and , seprate them when recieve them in another program ?
Posted

1 solution

Some common sense approaches might involve sending a string with two numbers seperated by a comma, or just plain knowing how many bytes there are in an int and so inserting and extracting them into your byte stream.
 
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