1. Home
  2. Computing & Technology
  3. Python

Classes: socket (Part 1)

From , former About.com Guide

    socket = class _socketobject(__builtin__.object)
        socket([family[, type[, proto]]]) -> socket object
        Open a socket of the given type. The family argument specifies the
        address family; it defaults to AF_INET. The type argument specifies
        whether this is a stream (SOCK_STREAM, this is the default)
        or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,
        specifying the default protocol. Keyword arguments are accepted.
        A socket object represents one endpoint of a network connection.
        Methods of socket objects (keyword arguments not allowed):
        accept() -- accept a connection, returning new socket and client address
        bind(addr) -- bind the socket to a local address
        close() -- close the socket
        connect(addr) -- connect the socket to a remote address
        connect_ex(addr) -- connect, return an error code instead of an exception
        dup() -- return a new socket object identical to the current one [*]
        fileno() -- return underlying file descriptor
        getpeername() -- return remote address [*]
        getsockname() -- return local address
        getsockopt(level, optname[, buflen]) -- get socket options
        gettimeout() -- return timeout or None
        listen(n) -- start listening for incoming connections
        makefile([mode, [bufsize]]) -- return a file object for the socket [*]
        recv(buflen[, flags]) -- receive data
        recvfrom(buflen[, flags]) -- receive data and sender's address
        sendall(data[, flags]) -- send all data
        send(data[, flags]) -- send data, may not send all of it
        sendto(data[, flags], addr) -- send data to a given address
        setblocking(0 1) -- set or clear the blocking I/O flag
        setsockopt(level, optname, value) -- set socket options
        settimeout(None float) -- set or clear the timeout
        shutdown(how) -- shut down traffic in one or both directions
         [*] not available on all platforms!
Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python
  4. Networking
  5. Python Network Programming : Python's socket Module - Part 2>

©2009 About.com, a part of The New York Times Company.

All rights reserved.