Networking C#/.NET接收UDP数据包
我使用的是OSX,我有一个MIDI键盘。在音频MIDI设置中,我将MIDI事件从键盘重定向到网络。它告诉我它正在使用端口5004: 注意:请注意,我已将“谁可以连接我”设置为“任何人”,并且在“实时路由”中,我已将MIDI键盘路由发送到网络中 现在,从一个C#/.NET脚本(在我的Unity3D项目中),我尝试侦听此端口:Networking C#/.NET接收UDP数据包,networking,udp,midi,udpclient,Networking,Udp,Midi,Udpclient,我使用的是OSX,我有一个MIDI键盘。在音频MIDI设置中,我将MIDI事件从键盘重定向到网络。它告诉我它正在使用端口5004: 注意:请注意,我已将“谁可以连接我”设置为“任何人”,并且在“实时路由”中,我已将MIDI键盘路由发送到网络中 现在,从一个C#/.NET脚本(在我的Unity3D项目中),我尝试侦听此端口: UdpClient udp; udp = new UdpClient( 5004 ) // <-- SocketException: Address already
UdpClient udp;
udp = new UdpClient( 5004 ) // <-- SocketException: Address already in use
System.Object myObj = null;
udp.BeginReceive(
new AsyncCallback( UDP_IncomingData ),
myObj // udp_ep
);
static void UDP_IncomingData( IAsyncResult ar )
{
Debug.Log( "GotData" );
//Get the data from the response
byte[] bResp = udp.EndReceive( ar, ref udp_ep );
//Convert the data to a string
string sResponse = Encoding.UTF8.GetString( bResp );
//Display the string
Console.WriteLine( sResponse );
//Close the UDP connection
udp.Close( );
}
UdpClient-udp;
udp=新UdpClient(5004)/“地址已在使用”并不意味着端口。。。?也许可以使用接受IPEndPoint的ctor重载,以便可以指定所有地址/端口组件?
udp = new UdpClient( 0 ); // <-- http://stackoverflow.com/questions/2456773/find-a-free-port
udp.Connect( "192.168.0.13", 5004 );