datagramsender.java
来自「包括及时通讯,音效,菜单显示等等java程序」· Java 代码 · 共 67 行
JAVA
67 行
/*
* @(#)DatagramSender.java 1.6 03/03/02
*
* Copyright (c) 2003 Qualcomm, Inc. All rights reserved.
* PROPRIETARY/CONFIDENTIAL
* Use is subject to license terms
*/
package com.qualcomm.demo.chatbypush;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import java.io.*;
public class DatagramSender extends Thread {
private DatagramConnection dc;
private String address;
private String message;
public DatagramSender(DatagramConnection dc) {
this.dc = dc;
start();
}
public synchronized void send(String addr, String msg) {
address = addr;
message = msg;
notify();
}
public synchronized void run() {
while(true) {
// If no client to deal, wait until one connects
if (message == null) {
try {
wait();
} catch (InterruptedException e) {
}
}
try {
byte[] bytes = message.getBytes();
Datagram dg = null;
// Are we a sender thread for the client ? If so then there's
// no address parameter
if (address == null) {
dg = dc.newDatagram(bytes, bytes.length);
} else {
dg = dc.newDatagram(bytes, bytes.length, address);
}
dc.send(dg);
} catch (Exception ioe) {
ioe.printStackTrace();
}
// Completed client handling, return handler to pool and
// mark for wait
message = null;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?