62,597
社区成员




java.lang.OutOfMemoryError: Failed to allocate a 842019138 byte allocation with 16777216 free bytes and 481MB until OOM
at fuhao.com.app.net.TcpSocketZ$ReceiveThread.run(TcpSocketZ.java:255)
@Override
public synchronized void run() {
try {
int packetLen = 0;
while (isRunning) {
if (!isConnected) {
mSocket = new Socket(HostIP, Port);
mSocket.setSendBufferSize(1024);
mSocket.setReceiveBufferSize(1024);
mSocket.setTcpNoDelay(true);
mSocket.setKeepAlive(true);
mDos = new DataOutputStream(mSocket.getOutputStream());
mDis = new DataInputStream(mSocket.getInputStream());
handshark();
isConnected = true;
startHeartBeat();
} else {
if (mDis.available() >= 4) {
packetLen = mDis.readInt();
L.e("TcpSocketZ", "-----packetLen------" + packetLen);
if (packetLen > 0) {
byte iszlib = mDis.readByte();
if (iszlib == (byte) 1) {
try {
byte[] inputData = new byte[packetLen - 1];
utils.readData(mDis, inputData, 0, packetLen - 1);
byte[] result = CompressUtil.decompress(inputData);
byteReader br = new byteReader(result);
int alias = br.readInt();
L.e("TcpSocketZ", "recv packet zlib ------" + String.valueOf(alias));
baseProto obj = ClassFactory.getProtoObject(alias);
if (obj != null) {
obj.parseFrom(br);
EventBus.getDefault().post(new ResEvent(obj));
}
} catch (DataFormatException e) {
e.printStackTrace();
}
} else {
byte[] inputData = new byte[packetLen - 1];
utils.readData(mDis, inputData, 0, packetLen - 1);
byteReader br = new byteReader(inputData);
int alias = br.readInt();
L.e("TcpSocketZ", "packet alias------" + String.valueOf(alias));
if (alias == 20002) {
backTime = 0;
}
baseProto obj = ClassFactory.getProtoObject(alias);
if (obj != null) {
obj.parseFrom(br);
EventBus.getDefault().post(new ResEvent(obj));
}
}
}
}
}
}
mDos.close();
mDis.close();
if (mSocket != null) {
mSocket.close();
mSocket = null;
}
this.isRunning = false;
reconnect();
} catch (EOFException e) {
this.isConnected = false;
try {
mDos.close();
mDis.close();
if (mSocket != null) {
mSocket.close();
mSocket = null;
}
} catch (IOException e1) {
e1.printStackTrace();
}
reconnect();
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
this.isConnected = false;
try {
mDos.close();
mDis.close();
if (mSocket != null) {
mSocket.close();
mSocket = null;
}
} catch (IOException e1) {
e1.printStackTrace();
}
reconnect();
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
this.isConnected = false;
try {
mDos.close();
mDis.close();
if (mSocket != null) {
mSocket.close();
mSocket = null;
}
} catch (IOException e1) {
e1.printStackTrace();
}
reconnect();
e.printStackTrace();
} catch (IOException e) {
this.isConnected = false;
try {
mDos.close();
mDis.close();
if (mSocket != null) {
mSocket.close();
mSocket = null;
}
} catch (IOException e1) {
e1.printStackTrace();
}
reconnect();
e.printStackTrace();
}
}
byte[] buf=new byte[1024];
while((by=bis.read(buf))!=-1)
{
bos.write(buf,0,by);
}