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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:36:09+00:00 2026-05-15T04:36:09+00:00

I have this socket server script, import SocketServer import shelve import zlib class MyTCPHandler(SocketServer.BaseRequestHandler):

  • 0

I have this socket server script,

import SocketServer
import shelve
import zlib

    class MyTCPHandler(SocketServer.BaseRequestHandler):
        def handle(self):
            self.words = shelve.open('/home/tipu/Dropbox/dev/workspace/search/words.db', 'r');
            self.tweets = shelve.open('/home/tipu/Dropbox/dev/workspace/search/tweets.db', 'r');

            param = self.request.recv(1024).strip()
            try:
                result = str(self.words[param])
            except KeyError:
                result = "set()"
            self.request.send(str(result))

    if __name__ == "__main__":
        HOST, PORT = "localhost", 50007
        SocketServer.TCPServer.allow_reuse_address  = True
        server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
        server.serve_forever()

And this receiver,

from django.http import HttpResponse
from django.template import Context, loader
import shelve
import zlib
import socket


def index(req, param = ''):
    HOST = 'localhost'    
    PORT = 50007              
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))
    s.send(param)
    data = zlib.decompress(s.recv(131072))
    s.close()
    print 'Received', repr(data)
    t = loader.get_template('index.html') 
    c = Context({ 'foo' : data })
    return HttpResponse(t.render(c))

I am sending strings to the receiver that are in the hundreds of kilobytes. I end up only receiving a portion of it. Is there a way that I can fix that so that the whole string is sent?

Edit: The string I am trying to send is actually 418437 characters. But here’s the idea.. I’m trying to send the string representation of a set, using str(set), so I can reassemble the set using eval. Is there a way can I either get the socket to send the complete data or compress it enough so that the socket can send it at once? I tried using zlib, but the compressed data doesn’t send completely either because I repeatedly get header errors which, from what I was able to find, is because the compressed string was incomplete.

  • 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-15T04:36:10+00:00Added an answer on May 15, 2026 at 4:36 am

    socket.recv(N) does not guarantee that exactly N bytes will be received: rather, N is just the maximum number of bytes that can be received at one gulp (and for efficiency it should ideally be a small multiple of 4096, as the docs suggest).

    You’ll need to “keep receiving” (looping and accumulating) until you have all the bytes you desire (and it looks like your protocol does not communicate that crucial value: you will have to make it explicit, either with a prefix length or a terminator at the end of transmission, there is no way it can be implicitly extracted from the stream socket).

    Similarly for sending, although for that case you can use socket.sendall which does the necessary looping on your behalf.

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

Sidebar

Ask A Question

Stats

  • Questions 514k
  • Answers 514k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It depends. I try to always use properties. Even though… May 16, 2026 at 6:06 pm
  • Editorial Team
    Editorial Team added an answer I don't know if I want to wade my way… May 16, 2026 at 6:06 pm
  • Editorial Team
    Editorial Team added an answer First, I think you want after() or insertAfter() (which places… May 16, 2026 at 6:06 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I now have a small java script server working correctly, called by: <?php $handle
I wrote two applictions which comunicate by socket. This is the code: Server: import
So I have a simple socket server on an android emulator. When I'm only
I have been creating an async server socket that sends and recives xml using
so - I have this Socket (not XMLSocket, just Socket) client. I also have
I have two simple Python files: client.py and server.py . The client simply sends
import socket irc = 'irc.hack3r.com' port = 6667 channel = '#chat' sck = socket.socket(socket.AF_INET,
I have a task to import/transform and extract zipped binary files that contain both
I have a python function that makes a subprocess call to a shell script
For a recent project, I have a PHP script running as a CLI-based daemon.

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.