在本地运行的tomcat Web服务器上无法接收UDP数据包

时间:2019-08-20 12:21:06

标签: java android servlets udp httpconnection

我已经开发了一个本地的tomcat服务器,该服务器具有一个UDP连接来接收udp数据包。该服务器还具有与Android应用程序的httpconnection。 httpconnection工作正常,但UDP连接现在失败了,我不再接收任何UDP数据包。我得到一个SocketTimeoutException。我可以对发送udp数据包的服务器执行ping操作,这很奇怪。

public void connect() throws IOException 
    {
         //Creates a datagramsocket, bound to the specified local address.
          socket = new DatagramSocket();
         //Sends a datagrampacket from this socket.

         DatagramPacket sendDatagramPacket = new DatagramPacket(message, message.length, local,
                 server_port);
       //Sends a datagrampacket from this socket.
         socket.send(sendDatagramPacket);
         System.out.println(sendDatagramPacket.getData().toString());

    }


    public void receive() throws IOException 
    {

         // Prepare a UDP-Packet that can contain the data we want to receive
        DatagramPacket receivePacket = new DatagramPacket(message, message.length);
        // Receive the UDP-Packet

      socket.setSoTimeout(30000);
        socket.receive(receivePacket);
        tryRead(receivePacket.getData());
        System.out.println("receivePacket.getData()");

    }

0 个答案:

没有答案