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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:44:31+00:00 2026-05-23T06:44:31+00:00

I trying to write a client server application in Python, but I faced a

  • 0

I trying to write a client server application in Python, but I faced a problem, in the client side I’m not getting all the sent data. First I tried to send the numbers 1 to 10 and I received 1,2,5,6,10, so there are missing a lot of numbers.

Server side:

def __init__( self ):
        super( MCCommunication, self ).__init__()

        HOST, PORT = socket.gethostbyname( socket.gethostname() ), 31000
        self.server = SocketServer.ThreadingTCPServer( ( HOST, PORT ), MCRequestHandler )
        ip, port = self.server.server_address        
        # Start a thread with the server
        # Future task: Make the server a QT-Thread...
        self.server_thread = threading.Thread( target = self.server.serve_forever )
        # Exit the server thread when the main thread terminates
        self.server_thread.setDaemon( True )
        self.textUpdated.emit( 'Server Started!' )
        print( 'Server Started!' )
        self.server_thread.start() 

def handle( self ):       
        #self.request.setblocking( 0 )
        i = 10;
        while True:
            if( self.clientname == 'MasterClient' ):                
                try:                    
                    #ans = self.request.recv( 4096 )
                    #print( 'after recv' )   
                    """    Sendign data, testing purpose    """                 
                    while i:
                        mess = str( i );            
                        postbox['MasterClient'].put( self.creatMessage( 0, 0 , mess ) )
                        i = i - 1

                    while( postbox['MasterClient'].empty() != True ):                        
                        sendData = postbox['MasterClient'].get_nowait()                        

                        a = self.request.send( sendData )
                        print( a );
                        #dic = self.getMessage( sendData )
                        #print 'Sent:%s\n' % str( dic )                         
                except:                    
                    mess = str( sys.exc_info()[0] )
                    postbox['MasterClient'].put( self.creatMessage( 1, 0 , mess ) )
                    pass

    def creatMessage( self, type1 = 0, type2 = 0, message = ' ', extra = 0 ):        
        return pickle.dumps( {"type1":type1, "type2":type2, "message":message, "extra":extra} );

Where the postbox['MasterClient'] is a Queue with the serialized message.

And this is the client:

def run( self ):        
        sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )        
        addr = ( self.ip, self.port )        
        #print addr
        sock.connect( addr )
        #sock.setblocking( 0 )
        while True:         
            try:   
                ans = sock.recv( 4096 )                
                dic = self.getMessage( ans )               
                self.recvMessageHandler( dic )  
                print 'Received:%s\n' % str( dic )       
            except:
               pass
  • 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-05-23T06:44:32+00:00Added an answer on May 23, 2026 at 6:44 am

    The server may have sent multiple messages by the time the client attempts to read them, and if these fit within the same 4k buffer, the recv() call will obtain both of them.

    You don’t show the getMessage code, but I’d guess you’re doing something like pickle.loads(msg), but this will only give you the first message and discard the rest of the string, hence the dropped messages. You’ll also get another issue if more than 4096 bytes are buffered by the time you read, as you could end up getting a fragment of a message and thus an unpickling error.

    You’ll need to break up the string you get back into seperate messages, or better, just treat the socket as a stream and let pickle.load pull a single message from it.

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

Sidebar

Related Questions

I'm trying to write a client-server application in Java with an XML-based protocol. But
I'm trying to write a client-server console application on C# using UDP. And i
I am trying to write a unit test for a client server application. To
I am trying to write a Server application wrapper, as I would with any
I am trying to write a server application that listens to both IPv6 and
I'm trying to secure a connection from a Java Client/Server application that communicates over
I am currently trying to design a client-server application, something like this: the user
I am trying to write a basic client-server program to allow the client to
My client/server application is using WCF for communication, which has been great. However one
My team is maintaining a huge Client Server win32 Delphi application. It is a

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.