j2me实现简单socket聊天(二)

2014-11-23 23:14:01 · 作者: · 浏览: 1
private Display display;
private Form form = new Form("服务器聊天");
private Command cmd = new Command("发送",Command.SCREEN,1);
private TextField tf_msg = new TextField("请输入:","",50,TextField.ANY);

private SocketConnection sc = null;
private DataInputStream dis = null;
private DataOutputStream dos = null;

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

}

protected void pauseApp() {

}

protected void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
display.setCurrent(form);
form.addCommand(cmd);
form.append(tf_msg);
form.setCommandListener(this);

try{

sc = (SocketConnection)Connector.open("socket://127.0.0.1:8888");
dos = sc.openDataOutputStream();
dis = sc.openDataInputStream();
new ChatThread().start();
&nb