Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys
it`s question about , sending data separately , im send one integer as info form my sensor to server program , i want to send another integer as another sensor to server but there is problem how separate them from each other , and how i can understand which on that i get it in my server program :
client program : Void send
<pre lang="cs">
void sendata(int d)
        {
            byte[] data = new byte[1024];
            data  = BitConverter.GetBytes(d);
            sock.Send(data, data.Length, SocketFlags.None);
        }


then i call this void in this timer and send data to server :
<pre lang="cs">
private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                sendata(a);
            }
            catch
            {
                //MessageBox.Show("error","er");
                //sock.Shutdown(SocketShutdown.Both);
                //sock.Close();
                //Close();
            }
        }

and use this code in server :
        private void timer1_Tick(object sender, EventArgs e)
        {
            DateTime startTime = DateTime.Now;
            byte[] data = new byte[1024];
            int recv = client.Receive(data);
            int size = BitConverter.ToInt32(data, 0);
            if (recv != 0)
            {
                label3.Text = " ";
                label3.Text = "co2 ppm is : " + size;
                // label4.Text=""+ siz;
            }
            progressBar1.Maximum = 100;
            progressBar1.Minimum = 0;
            progressBar1.Value = size;
            label2.Text = DateTime.Now.Subtract(startTime).TotalMilliseconds.ToString() + "         :Time To Action" + " ms ";
        }
please tell me how i can send two or more data (int) and get and separate them in server ...

Posted

1 solution

You need to write an application layer protocol:

http://en.wikipedia.org/wiki/Application_Layer[^]

Then you need to implement your protocol in both the client and server programs.

I don't mean to be rude, but if this is for work then you might want to hire someone to help you.

Nick
 
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