如何分别发送数据 [英] How sending data separately
本文介绍了如何分别发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
它的问题是,分别发送数据,我将一个整数作为信息从我的传感器发送到服务器程序,我想将另一个整数作为另一个传感器发送到服务器,但是存在一个问题,如何将它们彼此分开,以及我如何理解我在我的服务器程序中得到的内容:
客户端程序:无效发送
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 ...
推荐答案
您需要编写应用程序层协议:
http://en.wikipedia.org/wiki/Application_Layer [
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
这篇关于如何分别发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文