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 8706365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:35:47+00:00 2026-06-13T03:35:47+00:00

I have to integrate my application with an existing (not modifiable) Python script which

  • 0

I have to integrate my application with an existing (not modifiable) Python script which sends the JSON messages without ‘\0’ or any other “end-of-message” character. Is there any better way to handle incoming messages that just to read data from the socket byte after byte and count brackets? In this application sending { or } in message content is illegal due to the protocol so this code works fine but seems to me ugly:

  int i = 0;
  int brackets = 0;
  byte[] msg = new byte[4096];
  do
  {
       byte chunk = reader.readByte();
       msg[i++] = chunk;
       if (chunk == 123)  // check if '{'
           brackets++;
       else if (chunk == 125) // check if '}'
           brackets--;
  } while ( brackets > 0);
  byte[] finalMsg = Arrays.copyOfRange(msg, 0, i);

EDIT Python code:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server_ip, server_port))
logging.info('Connected to: %s', (server_ip, server_port))
s.send(json.dumps(data))
logging.info('Sent message: %s', json.dumps(data))

I analyse text using bytes because this script sends each character as a single byte and as far as I know char is 2 bytes long in Java. When I tried to receive data char-after-char I was not able to compare them with { and }.

  • 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-13T03:35:48+00:00Added an answer on June 13, 2026 at 3:35 am

    You coud use Gson library:

    Gson gson = new Gson();
    JsonReader jr = new JsonReader(reader);
    String msg1 = gson.toJson(gson.fromJson(jr, Object.class));
    String msg2 = gson.toJson(gson.fromJson(jr, Object.class));
    ...
    

    Where reader is input stream from socket reader.

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

Sidebar

Related Questions

I have integrate draw line in my application i have not used OpenGL or
I have a Java application that I need to integrate our existing PHP website
I have an existing ASP.NET web application that is for public use and any
I have to integrate PDF file in my iPad Application. So now, is it
Is it possible to have a Java/J2EE web application integrate/communicate with SharePoint to load,
I have a JSP struts application that uses Spring to integrate with the services/dao/database.
We have an asp.net mvc application that we would like to integrate a FileSystemWatcher
I have developed a window application in VS2005 using C#. I need to integrate
I have a php application , and I'm trying to integrate with paypal payment
I want to integrate the zxing source code to my Android application. I have

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.