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!
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 - http://evolt.org/node/60276/
I recommend bpython for experiments in python.