UdpClient,接收()右后发送()不起作用? [英] UdpClient, Receive() right after Send() does not work?

查看:185
本文介绍了UdpClient,接收()右后发送()不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的代码:

client.Send(data, data.Length, endpoint);
byte[] response = client.Receive(ref endpoint);



虽然,根据的是Wireshark(网络嗅探器),远程主机并用数据回答,
中的应用这里只是等待数据永远...它没有收到因某种原因远程主机的答案。

While, according to WireShark (network sniffer), the remote host does reply with data, the application here just waits for data forever... it does not receive the answer from the remote host for some reason.

任何想法?

推荐答案

您可能希望创建了两个UdpClients:一个是听,一个用于发送

You probably want to setup two UdpClients: one for listening, one for sending.

对于接收UdpClient,需要使用带有端口的构造。

For the receiving UdpClient, use the constructor that takes a port.

这篇关于UdpClient,接收()右后发送()不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆