SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Python Sockets

  1. #1
    SitePoint Member
    Join Date
    May 2009
    0 Post(s)
    0 Thread(s)

    Python Sockets

    Hello there,

    I'm currently working on a very simple script. It opens a socket and tries to read the incoming data. Currently I'm using the recv method which puts the entire incoming data in a single string variable. This is all fine but the package I'm receiving contains various data which I need to parse out.

    The pattern in the package is rather straightforward, the first incoming integer tells me how long the incoming string is and after that a second integer telling me how long the second string is and so it goes. Here is my problem, how do I fetch the first integer from a string? Not thinking this was possible at all I started to look at buffers (from the Java ByteArrayBuffer) but I didn't find what I was looking for. There was one method recv_into which takes a read-write buffer but I didn't quite get that.

    So, basically what I want to do is open a socket and read an integer or a string from that socket much similar to Java. Is this possible? I cannot be the first one trying out socket communication in Python!

    Kind regards,

  2. #2
    SitePoint Member ideamonk's Avatar
    Join Date
    Sep 2010
    0 Post(s)
    0 Thread(s)
    Surely you're not the first one, I suggest you try the echo server example from python's documentation page to get an understanding.

    Another tutorial -

    I recommend bpython for experiments in python.

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts