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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:40:33+00:00 2026-06-15T09:40:33+00:00

I need to create TCP chat with C++ clients and Python server(already started), I

  • 0

I need to create TCP chat with C++ clients and Python server(already started), I have messages in c++ class like

class Message{
public:
uint64 utc_time;
uint64 token;
string content;
};

I am sending this from client to server, on server I have priority queue by utc_time and need to broadcast to others. My question is how to serialize this, which format to use so to avoid any cross language dependencies on size type size ? (maybe is going to be more meta data in future so need kind a little generic) ? Can anyone give me advice which format to use for serialization(or to flush only like bytes) ?

class Persistent:
public:
    Persistent(int sz):objSize(sz){}
    void write(std::ostream& out)const{out.write((char*)this, objSize);}
    void read(std::istream& in){in.read((char*)this, objSize);}
private:
    int objSize;
};

I thought of other possibility to have deserializator in c++ on server and call from python if that is possible. Any elegant solution to this problem ?

  • 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-15T09:40:35+00:00Added an answer on June 15, 2026 at 9:40 am

    If you really want to go cross language and cross platform without having to worry about where the message ends, have a look at the combination of Google Protobuf and ZeroMQ.

    When using regular sockets you would first read the size of the message (you would prepend this) and then you would know from where to where the byte-array is a complete message.

    Example protobuf + zmq usage:

    message Message {
        optional uint64 utc_time = 1;
        required uint64 token = 2;
        optional string content = 3;
    }
    

    Use the protobuf compiler to generate C++ code (or ruby/python/etc).

    To use it in your code:

    #include <Message.pb.h>
    
    Message msg;
    msg.set_token(1);
    msg.set_content("Hello world");
    

    To send it using zmq:

    std::string serialized = msg.SerializeAsString();
    zmq::message_t reply(serialized.size());
    memcpy(reply.data(), serialized.data(), serialized.size());
    zmq_socket.send(reply);
    

    To receive it using zmq:

    zmq::message_t request;
    zmq_socket.recv(&request); // blocking
    Message recv_msg;
    recv_msg.ParseFromArray(request.data(), request.size());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple chat server that is driven by client polling. Clients
I have MVC-4 Web-API server, and I need to create HTTP client by hand
I have a chat server in C/Linux using TCP sockets. When using libev I
I have a TCP client-server setup where I need to be able to pass
I have a tcp chat program: server.c and client.c . The server is in
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass
I have dynamically created WrapPanel (_wp) with several Borders. And I need create handler
Need to create a custom DNS name server using C which will check against
I need to create a WP site which will have multiple subjects. Each subject
I need to create a class with two properties: LogOutput ExceptionOutput These properties (Actions<>)

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.