UDP

UDP

 

while  (true)
        {
            try
            {
                
//  接收数据
                datagramSocket.receive(datagramPacket);
                String instruction 
=  new String(datagramPacket.getData(),  0 , datagramPacket.getLength());
                
                System.out.println(instruction);
                
                String senddStr 
=  " from  remote server: "  +  instruction;
                
                System.out.println("datagramPacket
- port: "  +  datagramPacket.getPort());
                System.out.println("datagramPacket
- addr: "  +  datagramPacket.getAddress().getHostAddress());
                
                this.send(datagramPacket.getAddress().getHostAddress(), datagramPacket.getPort(), senddStr);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }

你可能感兴趣的:(UDP)