send and receive nearly arbitrary python objects with the standard library pickle object serialization module its dumps and loads calls convert python objects to and from byte stringsready for direct socket transferimport pickle pickle dumps([ ]on sending end convert to byte strings '\ \ ] \ (kckde string passed to sendreturned by recv pickle loads( [ on receiving end convert back to object for simpler types that correspond to those in the languagethe struct module provides the byte-string conversion we need as wellimport struct struct pack('>ii' '\ \ \ \ \ \ dstruct unpack('>ii' ( convert simpler types for transmission when converted this waypython native objects become candidates for socket-based transfers see for more on struct we previewed pickle and object serialization in but we'll learn more about it and its few pickleability constraints when we explore data persistence in in fact there are variety of ways to extend the basic socket transfer model for instancemuch like os fdopen and open for the file descriptors we studied in the socket makefile method allows you to wrap sockets in text-mode file objects that handle text encodings for you automatically this call also allows you to specify nondefault unicode encodings and end-line behaviors in text mode with extra arguments in just like the open built-in function because its result mimics file interfacesthe socket makefile call additionally allows the pickle module' file-based calls to transfer objects over sockets implicitly we'll see more on socket file wrappers later in this for our simpler scripts herehardcoded byte strings and direct socket calls do the job after talking with given connected clientthe server in example - goes back to its infinite loop and waits for the next client connection request let' move on to see what happened on the other side of the fence client socket calls the actual socket-related calls in client programs like the one shown in example - are even simplerin facthalf of that script is preparation logic the main thing to keep in mind is that the client and server must specify the same port number when opening their sockets and the client must identify the machine on which the server is network scripting