If we had used s.bind(('localhost', 80)) or s.bind(('127.0.0.1', 80)) we would still have a “server” socket,īut one that was only visible within the same machine. listen ( 5 )Ī couple things to notice: we used socket.gethostname() so that the socket gethostname (), 80 )) # become a server socket serversocket. SOCK_STREAM ) # bind the socket to a public host, and a well-known port serversocket. # create an INET, STREAMing socket serversocket = socket. Your browser did something like the following: Roughly speaking, when you clicked on the link that brought you to this page, With INET makes talking to arbitrary machines around the world unbelievably easy With good reason - the combination of sockets They were invented in Berkeley as part of the BSD flavor of Unix. Likely to be other forms of IPC that are faster, but forĬross-platform communication, sockets are about the only game in town. Web server it’s talking to uses both “server” sockets and “client” sockets. ![]() The clientĪpplication (your browser, for example) uses “client” sockets exclusively the “server” socket, which is more like a switchboard operator. So first, let’s make aĭistinction between a “client” socket - an endpoint of a conversation, and a Number of subtly different things, depending on context. Part of the trouble with understanding these things is that “socket” can mean a You’ll need to know how they work before dealing with But I’ll start by talking aboutīlocking sockets. Work with blocking and non-blocking sockets. Try to clear up the mystery of what a socket is, as well as some hints on how to Know what you’re doing (in which case this HOWTO isn’t for you!), you’ll getīetter behavior and performance from a STREAM socket than anything else. ![]() IPv4) sockets, but they account for at least 99% of I hope it will give you enough background to begin using them decently. It doesn’t cover the fine points (and there are a lot of them), but It’s not really a tutorial - you’ll still have work to do in getting things This is a 10,000 foot overview of sockets. Sockets are used nearly everywhere, but are one of the most severely
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |