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.
精彩评论