问题描述
publicclassclient{publicclient(){try{InetAddressBroadcastGroup=InetAddress.getByName("255.255.255.255");//构造数据接收端口(频率)MulticastSocketReceiver=newMulticastSocket(9050);//指定数据接收端口的数据广播组(波段)Receiver.joinGroup(BroadcastGroup);}catch(Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}publicstaticvoidSendData(StringMsg){byte[]b=newbyte[1024];DatagramPacketpacket;try{//字节序列b包括需要发送的数据b=Msg.getBytes();//构造一个数据包,BroadcastGroup是数据广播组标示符(波段),//ClientPort是数据广播目标端口(频率)。packet=newDatagramPacket(b,b.length,InetAddress.getByName("255.255.255.255"),9050);//发送数据包DatagramSocketSender=newDatagramSocket(9050);Sender.send(packet);}catch(Exceptione){}}publicstaticvoidmain(String[]args){SendData("READ");ReceiveData();}//数据接收方法publicstaticvoidReceiveData(){byte[]b=newbyte[1024];//构造一个空的数据包DatagramPacketpacket=newDatagramPacket(b,1024);StringInMsg;try{//接收数据MulticastSocketReceiver=newMulticastSocket(9050);Receiver.receive(packet);}catch(IOExceptione){}//丛数据包中获得接收到的数据b=packet.getData();InMsg=newString(b);System.out.println(InMsg);}为什么无法接收到C返回的数据
解决方案
解决方案二:
路过…………帮顶!!!!