简体   繁体   中英

send multiple headers python socket?

So, say I create a TCP socket in python, and the server I am authorizing to needs multiple headers sent at once to authorize, how would I go about this? As I am going to use socket.sendall to send them, then wait for the authorization handshake reply. After that, I need it to just wait for a data reply until it gets one, how would I do this also, because doesn't it close the socket if data is not received in a set amount of time? Is there some easy way to send this correctly or what? ~~Edit~~ My main question i guess is how to send a multi line packet? :)

A python socket of the type SOCK_STREAM , using the socket.sendall(data) function simply sends a string. Yep, data is just a string. Now, you can construct your own headers and lines and everything and put it in a string and tell the socket to send it all off towards the server.

Then just do socket.recv(buffer) where buffer is an integer of the number of bytes. And as Thomas Orozco said, tcp sockets can remain open for a very long time, so make sure the server gives a fairly prompt reply.

edit: Btw, TCP is a transportaion layer protocol, you can read up a bit more here : http://en.wikipedia.org/wiki/Transport_layer . Simply put, TCP will transport whatever you tell it to transport. In python, it's strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM