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

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

本文简介:

   sc.setSocketOption(KEEPALIVE, 0);

   sc.setSocketOption(RCVBUF, 128);

   sc.setSocketOption(SNDBUF, 128);

   // Get the input stream of the connection.

   DataInputStream is = sc.openDataInputStream();

   // Get the output stream of the connection.

   DataOutputStream os = sc.openDataOutputStream();

   // Read the input data.

   String result = is.readUTF();

   // Echo the data back to the sender.

   os.writeUTF(result);

   // Close everything.

   is.close();

   os.close();

   sc.close();

   scn.close();

 

7.4.2   Socket示例

其实前面已经说过了,在J2ME中使用SocketJ2SE中差不多,无非就是由服务端打开一个监听端口等待客户端请求该端口,下面我们还来看个具体的示例(该示例代码来自J2ME开发网 mingjava

 

package socket;

import javax.microedition.midlet.*;

import javax.microedition.io.*;

import javax.microedition.lcdui.*;

import java.io.*;

public class SocketMIDlet extends MIDlet implements CommandListener {

 private static final String SERVER = "Server";

 private static final String CLIENT = "Client";

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

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

go top