部分代码如下
connectServer()用来连接服务器
public void drawReceive()用来接收数据
public void connectServer(){
try{
SocketConnection connection = (SocketConnection)Connector.open("socket://59.64.158.197:"+SERVER_PORT);
connection.setSocketOption(SocketConnection.KEEPALIVE, 5);
connection.setSocketOption(SocketConnection.DELAY, 0);
connection.setSocketOption(SocketConnection.LINGER, 0);
io_in = connection.openDataInputStream();
io_out = connection.openDataOutputStream();
}catch(IOException ioe){
ioe.printStackTrace();
}
myClass.connected = true;
}
public void drawReceive(){
while(myClass.connected){
try{
DataBag dataBag = new DataBag(0,0,0,0,0,true,0);
dataBag.color = io_in.readInt();
dataBag.sX = io_in.readInt();
dataBag.sY = io_in.readInt();
dataBag.eX = io_in.readInt();
dataBag.eY = io_in.readInt();
= io_in.readInt();
dataBag.received = true;
(dataBag,);
}catch(IOException ioe){
ioe.printStackTrace();
myClass.exit();
}
}
}