⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sender.java

📁 手机游戏对战平台。自己做的一个东东。 支持多个手机联网打游戏;采用socket链接通信。 平台:J2ME&JAVA
💻 JAVA
字号:
package clientInf;


import java.io.DataOutputStream;
import java.io.IOException;

public class Sender extends Thread {
    private DataOutputStream os;
    private Serializable message;

    public Sender(DataOutputStream os) {
	this.os = os;
	start();
    }
    public synchronized void send(Serializable msg) {      
        System.out.println(msg.toString());
        System.out.flush();
	message = msg;
	notify();
    }
    public void close(){
    	try {
			os.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    public synchronized void run() {
	 while (true) {
            // If no client to deal, wait until one connects
            try {
                wait();
            } catch (InterruptedException e) {
                System.out.println(e);
            }
            try {
                message.serialize(os);
            } catch (Exception e) {
                System.out.println(e + "");
                try {
                    os.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                break;
            }
            message = null;
        }
   }
    public synchronized void stop() {
	message = null;
	notify();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -