Título: Ayuda con mi codigo. (Enviar buffer de imagen de c++ a java)(SOCKETS) Publicado por: 70N1 en 18 Diciembre 2015, 16:59 pm Estoy intentando hacer streaming capturando la pantalla del pc y enviando el buffer por socket a
java(Android). Al parecer mi codigo funciona bien pero al poco de iniciar el streaming me da error en java(Android) Alguna idea?. Este es mi codigo de c++: Código: byte* buffer=NULL; ULONG tamañobuffer=NULL; ULONG comprobacion = NULL; CapturarPantalla(buffer,tamañobuffer, 50); long int NetInt; NetInt = htonl((unsigned)tamañobuffer); send(s2, (char *)&NetInt, sizeof(long), 0); recv(s2,(char*)&comprobacion,sizeof(long),0); long int hostint = ntohl(comprobacion); printf("\n%lu\n", hostint); send(s2, (char*)buffer,(int) tamañobuffer, 0); Y mi codigo java es este : Código: private Runnable updateTask = new Runnable () { public void run() { int tamaño=0; try { InStream = new DataInputStream(btSocket.getInputStream()); tamaño= InStream.readInt(); } catch (IOException e) { e.printStackTrace(); } try { outStream= new DataOutputStream(btSocket.getOutputStream()); outStream.writeInt(tamaño); } catch (IOException e) { // TODO Bloque catch generado automáticamente e.printStackTrace(); } int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; int totalBytesRead = 0; int numBytesRead = 0; byte[] result = new byte[tamaño]; while (totalBytesRead != tamaño ) { try { numBytesRead = InStream.read(buffer); } catch (IOException e) { // TODO Bloque catch generado automáticamente e.printStackTrace(); } System.arraycopy(buffer, 0, result, totalBytesRead, numBytesRead); totalBytesRead += numBytesRead; } Bitmap bmp = BitmapFactory.decodeByteArray(result, 0, tamaño); ImageView image = (ImageView) findViewById(R.id.imageView1); image.setImageBitmap(bmp); buffer = null; totalBytesRead = 0; numBytesRead = 0; result=null; mHandler.postDelayed(updateTask, 20); } }; |