错误的套接字ID,流关闭错误+黑莓套接字连接

时间:2012-07-17 14:29:47

标签: sockets blackberry connection

我正在使用socketConnection在黑莓曲线9300中编写程序。当我尝试读取输入流时,我得到流关闭/错误的套接字ID错误。 你能告诉我可能是什么问题。

String url = Constants.SOCKET + serverIp + Constants.COLON + serverPort + UserInfo.getConnectionType();

//connection open
socketConne`enter code here`ction = (SocketConnection) Connector.open(url, Connector.READ_WRITE,true);

socketConnection.setSocketOption(SocketConnection.DELAY, 0);
socketConnection.setSocketOption(SocketConnection.KEEPALIVE, 1);
socketConnection.setSocketOption(SocketConnection.RCVBUF, 16834);
socketConnection.setSocketOption(SocketConnection.LINGER, 10);

outputStream = socketConnection.openDataOutputStream();

//Output stream deligated to Sender Object to send the command
sender = new Sender(outputStream);
sender.send(command);
inputStream = socketConnection.openDataInputStream();

//read inputstream
while (tobeRead < toRead && retryCount < 5) {
    try {
        if ((toRead - tobeRead) > 8192) {
            readBufferLength = 8192;
        } else {
            readBufferLength = (toRead - tobeRead);
        }
        buffer = new byte[readBufferLength + 1];

        bytesRead = inputStream.read(buffer, 0, readBufferLength);
        sb.append(new String(buffer, 0, bytesRead));
        tobeRead += bytesRead;
        totalBytesRead += bytesRead;
    } catch (Exception cce) {
    }
}

说如果要读取的字节数是5192.我得说2123字节然后它迭代循环,下次读取它失败。我在单独的线程中运行它。我使用WIFI网络进行连接

0 个答案:

没有答案