[Skip to Body]
Primary:
[Front Door]
[Schedule]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
-
[Assignment]
Groupings:
[EBoards]
[Examples]
[Handouts]
[Outlines]
[Readings]
Related Courses:
[CSC223 2007F (Davis)]
[CSC223 2004F (Rebelsky)]
Misc:
[SamR]
Back to Extreme Programming (2): A Philosophy of XP. On to Project Status Day.
This outline is also available in PDF.
Held: Tuesday, April 6, 2010
Summary: We consider Sockets, one of the simple standard mechanisms of program communication.
Related Pages:
Notes:
Overview:
filesthat can be read or written.
import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((socket.gethostname(), port)) s.listen(5) # 5 is how many pending connections we support (s2,address) = s.accept()
accept is a blocking call.
Your program pauses until a connection is made.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((hostname, port))
connect is typically a blocking
operation (although it can timeout).
connect takes one parameter. In this
case, it's a two-element tuple of host/port.
send and recv
send takes something of type bytesas a parameter.
encode
method.
send returns the number of bytes sent (which will be less
than or equal to the number of bytes you attempted to send.
recv takes the maximum number of bytes to receive. It
returns a bytes object.
decode
method.
send buffer data before sending.
The data are sent when the buffer fills or when you explicitly
flush the socket.
close.
recv and listen (and even
send) are potentially blocking operations.
will this blockpredicate.
setblocking(0)
settimeout()
select procedure
provided by the select module.
select takes four parameters
select returns a tuple of three lists
struct.pack
socket.htonl
socket.ntohl
One-shot responses
interestingresponse string (e.g., you can prefix the string with
Hello, play
The Name Game, or whatever.
One-shot responses, revisited
A dialog
A numeric dialog
socket.htonl and
socket.ntohl.
A chat server
Back to Extreme Programming (2): A Philosophy of XP. On to Project Status Day.
[Skip to Body]
Primary:
[Front Door]
[Schedule]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
-
[Assignment]
Groupings:
[EBoards]
[Examples]
[Handouts]
[Outlines]
[Readings]
Related Courses:
[CSC223 2007F (Davis)]
[CSC223 2004F (Rebelsky)]
Misc:
[SamR]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Tue May 11 12:40:53 2010.
The source to the document was last modified on Mon Jan 25 20:52:44 2010.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC323/2010S/Outlines/outline.17.html.
You may wish to
validate this document's HTML
;
;
http://creativecommons.org/licenses/by-nc/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.