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

源代码在线查看: sender.java

软件大小: 2186 K
上传用户: gsxyndll
关键词: socket JAVA ME 手机游戏
下载地址: 免注册下载 普通下载 VIP

相关代码

				package serverInf;
				
				
				import java.io.DataOutputStream;
				import java.io.IOException;
				
				public class Sender extends Thread {
				    private DataOutputStream os;
				
				    private Serializable message;
				    
				    private boolean ready=false;
				    public boolean isReady() {
				        return ready;
				    }
				
				    public Sender(DataOutputStream os) {
				        ready=false;
					this.os = os;
					start();
				    }
				
				    public synchronized void send(Serializable msg) {
				    	if(msg==null)System.out.println("sender's msg is null");
				        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
							System.out.println(""+e);
						}
				    }
				        
				    public synchronized void run() {
				        ready=true;
					while (true) {    	
						try {
				                    wait();
						} catch (InterruptedException e) {
						}
						if (message == null) {
							System.out.println("send's msg is null");
							break;
						   }
					           try {
				                        message.serialize(os);
				                   } catch (Exception e) {
				                        System.out.println("error happen in sender's run(): " + e);
				                        break;
				                   }
				                 message = null;
				    }
				   }
				
				}
							

相关资源