ExSocket.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:1k
源码类别:

J2ME

开发平台:

Java

  1. package exframework;
  2. import javax.microedition.io.SocketConnection;
  3. /**
  4.  * <p>Title: ExFramework</p>
  5.  *
  6.  * <p>Description: lizhenpeng</p>
  7.  *
  8.  * <p>Copyright: Copyright (c) 2005</p>
  9.  *
  10.  * <p>Company: LP&P</p>
  11.  *
  12.  * @author lipeng
  13.  * @version 1.0
  14.  */
  15. import javax.microedition.io.*;
  16. import java.io.*;
  17. import javax.microedition.lcdui.*;
  18. public class ExSocket implements AllAction
  19. {
  20.   SocketConnection conn;
  21.   byte[] readBuffer;
  22.   byte[] writeBuffer;
  23.   public ExSocket()
  24.   {
  25.     writeBuffer = new byte[4];
  26.     readBuffer = new byte[4];
  27.   }
  28.   public void allAction(MainForm form)
  29.   {
  30.     try
  31.     {
  32.       conn=(SocketConnection)Connector.open("socket://localhost:8070");
  33.       DataInputStream in = conn.openDataInputStream();
  34.       DataOutputStream out = conn.openDataOutputStream();
  35.       out.writeInt(1);
  36.       int imageSize = in.readInt();
  37.       readBuffer = new byte[imageSize];
  38.       in.read(readBuffer,0,imageSize);
  39.       Image image = Image.createImage(readBuffer,0,readBuffer.length);
  40.       form.append(image);
  41.     }
  42.     catch(Exception e)
  43.     {
  44.       System.out.print(e);
  45.     }
  46.   }
  47. }