我想在我的服务器代码中创建自定义事件。像 onMessageReceive() , onServerStarted() 等,我的服务器代码是:
Thread thread = new Thread(new Runnable() {
public void run() {
try {
String text;
DatagramPacket p1 = new DatagramPacket(message, message.length);
DatagramSocket s1;
try {
s1 = new DatagramSocket(server_port);
Log.d("UDP Server","Listening");
s1.receive(p1);
text = new String(message, 0, p1.getLength());
Log.d("Client Message",text);
stop(s1);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
}
}
});
thread.start();
我该怎么做 ?通过使用回调?在这方面需要帮助