连接在android服务器应用程序上由peer重置

时间:2011-09-13 11:35:17

标签: android sockets

我有一个名为MainActivity的Activity和一个名为CameraService的服务。 CameraService充当服务器并通过套接字侦听客户端。每当客户端通过MainActivity(和BroadcastReceiver)连接服务触发器时相机。当相机返回onActivityResult时,它使用CameraService的输出OutputStream(公共静态属性)将照片发送回客户端。

protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CAMERA) {

        try {
            byte[] bufferArray = new byte[(int)path.length()];

            Log.i(TAG, "Image size: " + Integer.toString(bufferArray.length));

            FileInputStream fis = new FileInputStream(path);
            BufferedInputStream bis = new BufferedInputStream(fis);
            bis.read(bufferArray, 0, bufferArray.length);
            CameraService.out.write(bufferArray, 0, bufferArray.length);

            CameraService.out.flush();

        } catch (IOException e) {
            Log.i(TAG, e.getMessage());
            Log.i(TAG, stackTraceToString(e));
        }

try { byte[] bufferArray = new byte[(int)path.length()]; Log.i(TAG, "Image size: " + Integer.toString(bufferArray.length)); FileInputStream fis = new FileInputStream(path); BufferedInputStream bis = new BufferedInputStream(fis); bis.read(bufferArray, 0, bufferArray.length); CameraService.out.write(bufferArray, 0, bufferArray.length); CameraService.out.flush(); } catch (IOException e) { Log.i(TAG, e.getMessage()); Log.i(TAG, stackTraceToString(e)); }

上面的代码通过CameraService.out OutputStream执行照片发送到客户端。问题是客户端重置连接(RST tcp标志),服务器无法发送整个映像。任何想法为什么会发生这种情况?

0 个答案:

没有答案