java 和C#之间用UDP通信问题
我用java写了一个手机端的UDP发送程序,用C#写了一个PC端的接收程序,不知道两者之间为什么通信不了,
手机端java发送程序:
public void run(){
try {
DatagramSocket socket = new DatagramSocket(3389);
InetAddress serverAddress = InetAddress.getByName("192.168.137.1");
String str = "hello evryboy";
byte data [] = str.getBytes();
DatagramPacket packet = new DatagramPacket(data,data.length,serverAddress,3388);
while(true){
socket.send(packet);
}
} catch (Exception e) {
e.printStackTrace();
}
}
PC端C#接收程序:
static void Main(string[] args)
{
int recv;
byte[] data = new byte[1024];
//得到本机IP,设置UDP端口号
IPEndPoint ip = new IPEndPoint(IPAddress.Any, 3389);
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
//绑定网络地址
newsock.Bind(ip);
Console.WriteLine("This is a Server, host name is {0}", Dns.GetHostName());
//等待客户机连接
Console.WriteLine("Waiting for a client");
//得到客户机IP
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint Remote = (EndPoint)(sender);
recv = newsock.ReceiveFrom(data, ref Remote);
Console.WriteLine("Message received from {0}: ", Remote.ToString());
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
}
另外我用java又写了个接收程序,c#写了个发送程序,java发,java可以收,C#发,C#可以收,但是java发,c#却收不到,
求大神指导!!
------解决方案--------------------C#这句不用指定ip吗?
IPEndPoint ip = new IPEndPoint(IPAddress.Any, 3389);
------解决方案--------------------请问你是这是组播还是点播,组播客户端需要加入组的
------解决方案--------------------你说我这么业余都没叹息,你叹息啥