开发者

how to receive multiple messages in UDP packet in android?

开发者 https://www.devze.com 2023-03-10 00:25 出处:网络
I have this code written in java and I have to implement it in android so I can receive a text messages each time the clients send a message. but the problem is the client can send only one time. what

I have this code written in java and I have to implement it in android so I can receive a text messages each time the clients send a message. but the problem is the client can send only one time. what to do please help.

Runnable UDPpacket = new Runnable() {
    public void run() 
    { 
        while(true){
        String text;
        int server_port = 12345;
        byte[] message = new byte[1500];
        DatagramPacket p = new DatagramPack开发者_StackOverflow社区et(message, message.length);
        DatagramSocket s = new DatagramSocket(server_port);
        s.receive(p);
        text = new String(message, 0, p.getLength());
        text = DisplayText(text);
        Log.d("Udp tutorial","message:" + text);
        s.close();
    }
    }
};
mainfunction()
{
    IDPpacket.run();
}


You don't say what your actual problem is but this is strange code. You should create the socket once and then just loop reading it.

0

精彩评论

暂无评论...
验证码 换一张
取 消