Socket programming

Jorgen Grahn grahn+nntp at snipabacken.se
Sun Jan 4 13:12:44 EST 2015


On Sat, 2015-01-03, Dan Stromberg wrote:
> On Sat, Jan 3, 2015 at 3:43 AM, pramod gowda <pramod.sp78 at gmail.com> wrote:
...

> data=client_socket.recv(1024)
> print(data)
> client_socket.close()
>
>
> But note that if you send 10 bytes into a socket, it could be received
> as two chunks of 5, or other strangeness. So you should frame your
> data somehow - adding crlf to the end of your send's is one simple
> way.

I like to think of it as "defining the protocol" rather than "framing
your data".  But it ends up as the same thing: making sure each end
knows when it should stop looking for more data and start /acting/ on
it.

And yes, you can't do much with a TCP soocket without setting up these
rules. It's important to see that noone does it /for/ you.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .



More information about the Python-list mailing list