问题描述
为什么下面的代码Debug调试没问题,放在网页上_udpClient.Receive阻塞?publicpartialclassUserControl1:UserControl{publicUserControl1(){InitializeComponent();ParameterizedThreadStartparameterizedThread=newParameterizedThreadStart(PlayScreen);ThreadOpenVideoThread=newThread(parameterizedThread);OpenVideoThread.IsBackground=true;OpenVideoThread.Start();}privatevoidPlayScreen(objectobj){UdpClient_udpClient=newUdpClient(58888);while(true){byte[]buffer=newbyte[1024*1024];IPEndPointpoint=newIPEndPoint(IPAddress.Any,0);buffer=_udpClient.Receive(refpoint);放在浏览器上这里会阻塞MemoryStreammemoryStream=newMemoryStream();memoryStream.Write(buffer,0,buffer.Length);memoryStream.Position=0;Bitmapbitmap=newBitmap(memoryStream);BitmapnewBitmap=KiResizeImage(bitmap,500,400);this.pictureBox1.Image=newBitmap;memoryStream.Close();}}
解决方案
解决方案二:
因为客户端的Receive在等待接收服务端发送的数据,如果服务端没有数据发过来,它就只能阻塞直到接收到数据
解决方案三:
回复一楼,服务端有不停的发送数据
解决方案四:
因为没有收到数据呗这段代码是服务端代码,你要把UDP数据发到服务器端口上才行客户端只不过是个IE,不会响应UDP请求的
解决方案五:
那还可以用udp或tcp么?