J2ME中文教程 7 开发无线网络应用程序[31]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

   sc = (SocketConnection) scn.acceptAndOpen();

   si.setText("Connection accepted");

   is = sc.openInputStream();

   os = sc.openOutputStream();

   sender = new Sender(os);

   // Allow sending of messages only after Sender is created

   f.addCommand(sendCommand);

   while (true) {

    StringBuffer sb = new StringBuffer();

    int c = 0;

    while (((c = is.read()) != '\n') && (c != -1)) {

     sb.append((char) c);

    }

    if (c == -1) {

     break;

    }

    si.setText("Message received - " + sb.toString());

   }

   stop();

   si.setText("Connection is closed");

   f.removeCommand(sendCommand);

  } catch (IOException ioe) {

   if (ioe.getMessage().equals("ServerSocket Open")) {

    Alert a = new Alert("Server", "Port 5000 is already taken.",

      null, AlertType.ERROR);

    a.setTimeout(Alert.FOREVER);

    a.setCommandListener(this);

    display.setCurrent(a);

本文关键:J2ME中文教程 7 开发无线网络应用程序
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top