ExSocket.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:1k
源码类别:
J2ME
开发平台:
Java
- package exframework;
- import javax.microedition.io.SocketConnection;
- /**
- * <p>Title: ExFramework</p>
- *
- * <p>Description: lizhenpeng</p>
- *
- * <p>Copyright: Copyright (c) 2005</p>
- *
- * <p>Company: LP&P</p>
- *
- * @author lipeng
- * @version 1.0
- */
- import javax.microedition.io.*;
- import java.io.*;
- import javax.microedition.lcdui.*;
- public class ExSocket implements AllAction
- {
- SocketConnection conn;
- byte[] readBuffer;
- byte[] writeBuffer;
- public ExSocket()
- {
- writeBuffer = new byte[4];
- readBuffer = new byte[4];
- }
- public void allAction(MainForm form)
- {
- try
- {
- conn=(SocketConnection)Connector.open("socket://localhost:8070");
- DataInputStream in = conn.openDataInputStream();
- DataOutputStream out = conn.openDataOutputStream();
- out.writeInt(1);
- int imageSize = in.readInt();
- readBuffer = new byte[imageSize];
- in.read(readBuffer,0,imageSize);
- Image image = Image.createImage(readBuffer,0,readBuffer.length);
- form.append(image);
- }
- catch(Exception e)
- {
- System.out.print(e);
- }
- }
- }