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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:11:14+00:00 2026-06-12T09:11:14+00:00

I tried using a socket for 2 sends. The first one succeeds and the

  • 0

I tried using a socket for 2 sends. The first one succeeds and the next one does not.
From the http://docs.python.org/howto/sockets.html
it would appear that multiple sends should be allowed. For Better or worse, I don’t really need to read from the socket.
I have used twisted, but for the present purpose, I would like to stick to a socket, if I can help it(partly because I am using it within an application already using twisted to communicate.. this is a seperate connection).

“When the connect completes, the socket s can be used to send in a request for the text of the page. The same socket will read the reply, and then be destroyed. That’s right, destroyed. Client sockets are normally only used for one exchange (or a small set of sequential exchanges).”

return value for the send that succeeds = 35
return value for the send that FAILS = 32

code with some minor editing to remove any business logic.

self._commandSock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)


def sendPrereqs(self,id,prereqs):
    self._commandSock.connect(self._commandConnection)
    #parse prereqs
    temp = prereqs.split(',')
    for pair in temp:
        tup = pair.partition(':')
        try:
            command = 'some command'
            logging.info('sending command: ' + command)
            ret = self._commandSock.send(command)
            if ret == None:
                logging.info('send called successfully: ' + command)
            else:
                logging.info('socket returned non-None: ' + str(ret))
        except:

            print 'Unexpected Exception ', sys.exc_info()[0]()
            print sys.exc_info()
            #logging.info('Unexpected Exception '+ str(sys.exc_info()[0]()))
            #logging.info(' ' + str(sys.exc_info()))
    self._commandSock.close()`
  • 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-12T09:11:15+00:00Added an answer on June 12, 2026 at 9:11 am

    return value for the send that succeeds = 35 return value for the send that FAILS = 32

    Documentation says that successful send should return None.

    No it doesn’t. Documentation says:

    Returns the number of bytes sent. Applications are responsible for checking that all data has been sent; if only some of the data was transmitted, the application needs to attempt delivery of the remaining data. For further information on this concept, consult the Socket Programming HOWTO.

    You still haven’t explained what you mean by "FAILS". The send call is returning successfully, and it’s almost certainly placed 32 bytes into the socket write buffer.

    If the only reason you think it’s failing is that it returns the correct value, then the answer is obviously that it’s not failing.

    If something else is going wrong, there are all kinds of things that could be wrong at a higher level. One likely one is this: The server (especially if it was coded by someone who doesn’t understand sockets well) is coded to expect one recv() of 35 bytes, and one recv() of 32 bytes. But it’s actually getting a single recv() of 67 bytes, and waiting forever for the second, which never comes. There is no rule guaranteeing that each send() on a stream (TCP) socket corresponds to one recv() on the other side. You need to create some kind of stream protocol that demarcates the separate messages.

    Meanwhile, the quote you’re referring to is irrelevant. It’s describing how client sockets are used by simple web browsers: They make a connection, do one send, receive all the data, then destroy the connection. I can see why it misled you, and you may want to file a documentation bug to get it improved. But for now, just ignore it.

    If you want to make absolutely sure that the client is sending the right data, and the problem is in the server, there are two easy ways to do that:

    1. Use netcat as a trivial substitute server (e.g., nc -kl 6000, replacing the "6000" with the actual port) and making sure it logs what you think the server should be seeing.

    2. Use Wireshark to watch the connection between the client and server.

    Once you’ve verified that the problem is on the server side, you need to debug the server. If you need help with that, that’s probably best done in a new question, where you can post the server code instead of the client, and explain (with a link here) that you’re sure the client is sending the right information.

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

Sidebar

Related Questions

The following code sends messages from child processes to their parents using socket pairs.
I tried using curl syntax: curl http:// localhost:8983/solr/update/csv?stream.file=/usr/local/src/apache-solr-3.6.0/example/exampledocs/my+file.csv&separator=;&stream.contentType=text/plain;charset=utf-8 with no luck. I get: -bash:
I tried using axis2 1.6 (and nightly 1.7) to generate Java code from the
I tried using PHPDoc for the first time today and quickly ran into a
At the first look when using asynchronous methods on the socket level, there shouldn't
I'm using a Socket to communicate with a ServerSocket. Strings are being sent from
I'm trying to mock out the System.net.Sockets.Socket class in C# - I tried using
I have a little example running that sends a message through a socket from
Is it possible to force all clients to update using socket.io? I've tried the
I tried using arrays but I don't need every single element, and so it

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.