Kaydet (Commit) 27e177d0 authored tarafından Guido van Rossum's avatar Guido van Rossum

fixed up comments describing interface

üst f4b012a9
...@@ -30,43 +30,42 @@ This module provides an interface to Berkeley socket IPC. ...@@ -30,43 +30,42 @@ This module provides an interface to Berkeley socket IPC.
Limitations: Limitations:
- only AF_INET and AF_UNIX address families are supported - only AF_INET and AF_UNIX address families are supported
- no asynchronous I/O (but you can use select() on sockets)
- no read/write operations (use send/recv or makefile instead) - no read/write operations (use send/recv or makefile instead)
- setsockopt() and getsockopt() only support integer options
Interface: Module interface:
- socket.gethostname() --> host name (string) - socket.error: exception raised for socket specific errors
- socket.gethostbyname(hostname) --> host IP address (string: 'dd.dd.dd.dd') - socket.gethostbyname(hostname) --> host IP address (string: 'dd.dd.dd.dd')
- socket.gethostbyaddr(IP address) --> (hostname, [alias, ...], [IP addr, ...]) - socket.gethostbyaddr(IP address) --> (hostname, [alias, ...], [IP addr, ...])
- socket.getservbyname(servername, protocolname) --> port number - socket.gethostname() --> host name (string: 'spam' or 'spam.domain.com')
- socket.getservbyname(servicename, protocolname) --> port number
- socket.socket(family, type [, proto]) --> new socket object - socket.socket(family, type [, proto]) --> new socket object
- family and type constants from <socket.h> are accessed as socket.AF_INET etc. - socket.AF_INET, socket.SOCK_STREAM, etc.: constants from <socket.h>
- errors are reported as the exception socket.error
- an Internet socket address is a pair (hostname, port) - an Internet socket address is a pair (hostname, port)
where hostname can be anything recognized by gethostbyname() where hostname can be anything recognized by gethostbyname()
(including the dd.dd.dd.dd notation) and port is in host byte order (including the dd.dd.dd.dd notation) and port is in host byte order
- where a hostname is returned, the dd.dd.dd.dd notation is used - where a hostname is returned, the dd.dd.dd.dd notation is used
- a UNIX domain socket is a string specifying the pathname - a UNIX domain socket address is a string specifying the pathname
Socket methods: Socket methods:
- s.accept() --> new socket object, sockaddr - s.accept() --> new socket object, sockaddr
- s.setsockopt(level, optname, flag) --> Py_None - s.bind(sockaddr) --> None
- s.getsockopt(level, optname) --> flag - s.close() --> None
- s.bind(sockaddr) --> Py_None - s.connect(sockaddr) --> None
- s.connect(sockaddr) --> Py_None - s.fileno() --> file descriptor
- s.getsockname() --> sockaddr
- s.getpeername() --> sockaddr - s.getpeername() --> sockaddr
- s.listen(n) --> Py_None - s.getsockname() --> sockaddr
- s.getsockopt(level, optname[, buflen]) --> int or string
- s.listen(backlog) --> None
- s.makefile([mode[, bufsize]]) --> file object - s.makefile([mode[, bufsize]]) --> file object
- s.recv(nbytes [,flags]) --> string - s.recv(buflen [,flags]) --> string
- s.recvfrom(nbytes [,flags]) --> string, sockaddr - s.recvfrom(buflen [,flags]) --> string, sockaddr
- s.send(string [,flags]) --> nbytes - s.send(string [,flags]) --> nbytes
- s.sendto(string, [flags,] sockaddr) --> nbytes - s.sendto(string, [flags,] sockaddr) --> nbytes
- s.setblocking(1 | 0) --> Py_None - s.setblocking(0 | 1) --> None
- s.shutdown(how) --> Py_None - s.setsockopt(level, optname, value) --> None
- s.close() --> Py_None - s.shutdown(how) --> None
- repr(s) --> "<socket object, fd=%d, family=%d, type=%d, protocol=%d>" - repr(s) --> "<socket object, fd=%d, family=%d, type=%d, protocol=%d>"
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment