private void service()
{
//Buffer for reading data
Byte[] bytes = new Byte[10000];
String data = null; data = null; //Get a stream object for reading and writing
NetworkStream stream = client.GetStream();
int i;
///////int i = stream.Read(bytes, 0, bytes.Length); while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
//Translate data bytes to a ASCII string
data = System.Text.Encoding.UTF8.GetString(bytes, 0, i);
this.listBox1.Items.Add("接受数据:" + data); data = data.ToUpper();
byte[] msg = System.Text.Encoding.UTF8.GetBytes(data); //Send a response
stream.Write(msg, 0, msg.Length); this.listBox1.Items.Add("发送数据:" + data);
}
client.Close();
}上面这个方法我用来处理来自客户端的数据,但当接受了从GPRS和PDA上的数据后,处理的方法不一样,GPRS的要走while循环 可PDA的不用走循环为什么?
{
//Buffer for reading data
Byte[] bytes = new Byte[10000];
String data = null; data = null; //Get a stream object for reading and writing
NetworkStream stream = client.GetStream();
int i;
///////int i = stream.Read(bytes, 0, bytes.Length); while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
//Translate data bytes to a ASCII string
data = System.Text.Encoding.UTF8.GetString(bytes, 0, i);
this.listBox1.Items.Add("接受数据:" + data); data = data.ToUpper();
byte[] msg = System.Text.Encoding.UTF8.GetBytes(data); //Send a response
stream.Write(msg, 0, msg.Length); this.listBox1.Items.Add("发送数据:" + data);
}
client.Close();
}上面这个方法我用来处理来自客户端的数据,但当接受了从GPRS和PDA上的数据后,处理的方法不一样,GPRS的要走while循环 可PDA的不用走循环为什么?
解决方案 »
- 第二张贴,进程的关闭,软件的关闭,在线等
- WINFORM MessageBox.Show()的疑问??!!
- 如何将Dictionary作为DataTable的一个数据列,并将Dictionary类型的数据保存到xml文件中?
- a=3,则 a=b+1 ,a=b+2,=b+3, 问题,想不明白了,各位来帮忙看看。
- 如何获得其他程序中Listview每个item的字体颜色?
- 会员推广链接的问题?
- C#文件保存问题
- 请教!新人分不多,一下给了100,所以一下多提几个问题,希望能得到解答,谢谢~
- winform 程序访问网址
- 如何制作一个像word那样的启动画面?
- 用 c# 作即时通讯的问题,老不明白
- 关于listbox大小的运算
private void listen()
{
try
{
//Set the TcpListener on the port
Int32 port = 8081;
IPAddress ipAddress = IPAddress.Parse("192.168.1.222"); tcpListener = new TcpListener(ipAddress, port);
//Start Listening for client requests
tcpListener.Start(); this.listBox1.Items.Add("服务器已经启动.....");
while (true)
{ //Get a socket object to accept requests
client = tcpListener.AcceptTcpClient();
///////// clientSend = client;
this.listBox1.Items.Add("有客户连接上!");
thread1 = new Thread(new ThreadStart(service));
thread1.Start();
} }
catch (SocketException e)
{
MessageBox.Show("SocketException :" + e.ToString());
}
finally
{
tcpListener.Stop();
}
}