Difference between revisions of "Socket Programming in Python"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (New page: =References= * http://www.amk.ca/python/howto/sockets/ Category:Python Category:Network Category:Socket) |
PeterHarding (talk | contribs) |
||
Line 2: | Line 2: | ||
* http://www.amk.ca/python/howto/sockets/ | * http://www.amk.ca/python/howto/sockets/ | ||
=Examples= | |||
==Client== | |||
<pre> | |||
#!/usr/bin/env python | |||
# Create an INET, STREAMing socket | |||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |||
#now connect to the web server on port 80 - the normal http port | |||
s.connect(("www.performiq.com.au", 80)) | |||
</pre> | |||
==Simple Server== | |||
<pre> | |||
#!/usr/bin/env python | |||
# Create an INET, STREAMing socket | |||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |||
# Bind the socket to a public host ip, and a well-known port | |||
serversocket.bind((socket.gethostname(), 80)) | |||
# Become a server socket | |||
serversocket.listen(5) | |||
</pre> | |||
[[Category:Python]] | [[Category:Python]] | ||
[[Category:Network]] | [[Category:Network]] | ||
[[Category:Socket]] | [[Category:Socket]] |
Revision as of 16:10, 31 August 2008
References
Examples
Client
#!/usr/bin/env python # Create an INET, STREAMing socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #now connect to the web server on port 80 - the normal http port s.connect(("www.performiq.com.au", 80))
Simple Server
#!/usr/bin/env python # Create an INET, STREAMing socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Bind the socket to a public host ip, and a well-known port serversocket.bind((socket.gethostname(), 80)) # Become a server socket serversocket.listen(5)