Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7925165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:09:51+00:00 2026-06-03T18:09:51+00:00

i am developing an android application wherein i have to send a frame in

  • 0

i am developing an android application wherein i have to send a frame in jpeg format allocated to a BufferedArrayOutputStream (baos variable in code). I convert this baos into a byte array to write into the socket.
On the server side i would like to reconstruct the image in jpeg format. If i write the data received in a variable to a ‘.jpg’ file on the server, on opening the file, it gives an error like “file starting with ffx0 not jpeg format”. I think this is because the string variable in python writes the data in the file as a hex string.
The client code is as follows :-

Bitmap memoryImage = Bitmap.createBitmap(rgb, previewSize.width,previewSize.height,Bitmap.Config.ARGB_8888);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if(memoryImage.compress(CompressFormat.JPEG,100, baos)){
    try {
        if(count==0){
            byte [] Finalbaos = baos.toByteArray();
            int tempLen = Finalbaos.length;
            Log.v("Client","ImageBytes :"+ tempLen);
            String dataMeta = Integer.toString(tempLen);
            Log.v("Client","Integer Size :"+ dataMeta.length());
            PrintWriter tempOut = new PrintWriter(socket.getOutputStream());
            if(tempOut!=null){
                tempOut.write(dataMeta);
                Log.v("Client","data size sent");
                tempOut.flush();
            }

            DataInputStream in = new DataInputStream(socket.getInputStream());
            if(in!=null){
                Log.v("Client","read buffer created");
                String xyz = in.readLine();
                String temp = "recvd";
                Log.v("Client",xyz);
                if(xyz.equals(temp)){
                    OutputStream out = socket.getOutputStream();
                    out.write(Finalbaos,0,tempLen);
                    out.flush();
                    Log.d("Client", "Client sent message");
                }
            }

server code:

import socket,thread
import string
import array
host=""
port=54321
s=socket.socket()
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind((host,port))
s.listen(5)
conn,address=s.accept()
data=""
mylen=0
dataRecv=0
file1 = open("myfile.jpg","w")
totalLength=""
length=conn.recv(1024)
conn.send("recvd")
mylen=int(length)

while dataRecv<mylen:
    newData=""
    newData=conn.recv(1)
    if not newData:
        break
    data+=newData
    dataRecv+=len(newData)

result= array.array('B',data.decode("hex"))
file1.write(result)
file1.close()
print len(data)
conn.close()
s.close()

can anyone let me know how to reconstruct the frame on server either in python or C++

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:10:01+00:00Added an answer on June 3, 2026 at 6:10 pm
    • mylen=len(length) doesn’t give you the length you’re trying to send. it gives you how many bytes were read in the previsous recv. So you get the wrong lenght there.
    • on your client side, you use String xyz = in.readLine(); which will block until a newline character is encountered. but you never send a '\n' on the server side, instead you go waiting for a response from the client. so you have a deadlock there.
    • you use data.decode("hex") on your recieved data. unless you do the equivalend of data.encode("hex") in java on the other side, that won’t work. it should give you an error if the string is not a valid hex-representation of a binary string.
    • result is an array.array, which you write to file. file1.write expects a string as argument, it gives you an error if you pass your result object.

    so i can’t even see why your code works at all, and why there’s anything at all in your file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing Android application where I use this code: Date d=new Date(new
I am developing an application in android. I have situation wherein I have the
I am developing android application in which i want to convert html code in
I am developing android application in which i have to open option menu from
I have been developing Android application for Android 3.x and now I want to
I have been developing Android application and I can't make 1 thing - my
I have been developing Android application, and I have one question - ListView uses
I have been developing Android application which has 3 ListView and one ContextMenu for
I have been developing Android application, and I need to read PDF-files in my
Hi i am developing android application which read the QR Code. Now for that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.