socket

40 tutorials Updated 16 Sep 2024

  1. 1 accept function of Python socket class The accept() function accepts a connect request from a TCP client socket. It returns a socket that is connected to the client and this connected socket is used for the communication between the client and server. The example server program in Python accepts connections from clients and serves them the current server time. 26 Jun 2019
  2. 2 bind() function of socket module in Python The bind() function assigns an IP address and a port number to a socket. Generally, bind() is called on server sockets as it is required for server programs to publish their IP address and Port number for the to connect to them. The Python examples implement a simple echo server and echo client using the socket functions. 25 Jun 2019
  3. 3 Byte Ordering and Conversion Functions in python socket module A set of conversion functions in Python socket module convert positive integers from network byte ordering to host byte ordering and vice versa 7 Feb 2017
  4. 4 Python Client-Server program using socket module Client-Server program in python using socket module involves creating socket objects in client and server sides, accepting connections at server side 27 Jan 2017
  5. 5 Connect Function Of Python Socket Class The connect() function of python socket class is used to connect a tcp client socket i.e.,a streaming client socket, to a tcp server socket i.e., a streaming server socket. Address families like socket.AF_INET or socket.AF_INET6 to be specified during the creation of the socket.The python example creates a whois client, i.e., a client socket that queries a whois server using TCP. 25 Jun 2019
  6. 6 create_connection() in python create_connection() is a wrapper over the connect() and it establishes a connection with a TCP socket using host names, IPv4 and IPv6 addresses 2 Feb 2017
  7. 7 create_server function of Python socket module The create_server() function of socket module in Python creates a socket and binds it to an address and port. 13 Nov 2022
  8. 8 getaddrinfo() function in Python getaddrinfo() function of socket module returns a list of tuples for a given network service with which sockets can be created to connect to that service 2 Feb 2017
  9. 9 getfqdn() - Get the fully qualified domain name of a host using Python The getfqdn() method of Python's socket module returns the fully qualified domain name of a computer on the internet. The example Python program uses getfqdn() method to get the FQDN of the local host and example.net. 21 Jun 2019
  10. 10 gethostbyaddr() function in Python Given an IP address, the gethostbyaddr() function in Python returns a tuple with host name, aliases and the list of ip addresses for that host interface 3 Feb 2017
  11. 11 gethostbyname() function in Python The gethostbyname() function of socket module returns the IP address of a given host name. The returned address is an IPv4 address. 2 Feb 2017
  12. 12 gethostbyname_ex() function The gethostbyname_ex() function in Python takes a host name and returns a tuple containing host name, aliases and other ip addresses of the host 2 Feb 2017
  13. 13 gethostname() function in Python The python function gethostname(), returns the host name of the system under which the python interpreter is executed. 2 Feb 2017
  14. 14 getnameInfo() in Python The getnameInfo() method in Python returns the text or numeric values for the IP and Port information of a socket tuple. The text or numeric output is controlled by the flag values like NI_NAMEREQD. The Python example program prints the output for NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST and NI_NUMERICSERV flag values. 22 Jun 2019
  15. 15 getprotobyname() function in Python The getprotobyname() function of Python returns a constant corresponding the protocol string passed. Protocol string is case-insensitive. 7 Feb 2017
  16. 16 getservbyname() function in Python The getservbyname() function in Python takes a service name and the protocol name and returns the defined port of the service. 7 Feb 2017
  17. 17 getservbyport() - Get service name from port number using Python The getservbyport() function in Python's socket module returns the string representing the service corresponding to the port number. The example python program retrieves service name for the port numbers 21, 105, 80 and 443 which are ftp, cso, http and https. 22 Jun 2019
  18. 18 has_dualstack_ipv6() function of Python socket module The socket function has_dualstack_ipv6() detects the support of IPv6 and returns true if both IPv4 and IPv6 are supported in creating a TCP or an UDP socket. 13 Nov 2022
  19. 19 The htonl() function in Python The htonl() function converts an integer from host byte order to network byte order and returns the converted integer. If the byte order of the parameter and the platform is the same then no conversion is done. 31 Aug 2024
  20. 20 The htons() function in Python The htons() function of the socket module in Python converts a 16-bit integer from host byte order to network byte order. Host byte order is predominanatly little endian and network byte order is big endian. 3 Sep 2024
  21. 21 The inet_aton() function in Python The inet_aton function of python socket module converts an ip address from the dotted-quad string format to the 32 bit packed binary format. 31 Jan 2017
  22. 22 python inet_ntoa function The inet_ntoa function of python socket module converts an ip address of 32 bit packed format to dotted-quad string format. 31 Jan 2017
  23. 23 inet_ntop() - Convert an IP address in binary format to a string using Python The inet_ntop() function from socket module of Python converts an IP address in packed binary format to string format. The Python example program converts the IP address from a binary string b"xc0x00x02xff" to a string "192.0.2.255" which is in human readable format. 24 Jun 2019
  24. 24 inet_pton - Convert an IP address in string format to packed binary format using Python The inet_pton() function in the socket module of Python converts an IP address in string format to packed binary format. The Python examples convert an IPv4 address and an IPv6 address from string format to packed binary format. 24 Jun 2019
  25. 25 socket module in python The socket module in Python provides the BSD socket interface and has all constants, functions, objects and exceptions for the network programming defined. 26 Jan 2017
  26. 26 listen() function of socket class in Python The listen() function makes a tcp socket ready for accepting incoming connections from clients. The listen() should be called before calling the accept() method. The Python example program illustrates the role of listen() by implementing a Quote of the Day server and the associated client. 26 Jun 2019
  27. 27 makefile() method of socket class The makefile() method of socket class from the socket module of Python library returns the file object associated with a socket. 20 Nov 2022
  28. 28 The ntohl() function in Python The ntohl() function in Python converts a 4 byte integer from network byte order to host byte order. Network byte order is big endian and the hosts are predominantly little endian. 1 Sep 2024
  29. 29 The ntohs() function in Python The ntohs() function converts a 16-bit integer from network byte order to host byte order. 3 Sep 2024
  30. 30 Recv Function Of Python Socket Class The recv() function of socket module in Python receives data from sockets. Using recv(), a UDP server can receive data from a client and vice-versa.Similarly it can be used by a TCP server to receive data from a TCP client and vice-versa. 27 Jun 2019
  31. 31 recv_fds() function of socket module in Python The recv_fds() functions receives file descriptors from a server socket using Unix Domain Protocol. In the Python example, the client sends the file names to the server and gets the descriptors to read from files and to print onto the console. 19 Nov 2022
  32. 32 recvfrom() Function Of Python Socket Class recvfrom() reads a specified number of bytes from a socket, generally an UDP socket. It returns the message read and the client address in a tuple.Client address consists of an IP address and a port number. The Python example code uses recvfrom() in an UDP server and an UDP client. 30 Jun 2019
  33. 33 recvmsg() function of python socket class The recvmsg() function gets messages from connected sockets(TCP), unconnected sockets(UDP) and unix domain sockets. The message received is returned in a tuple consisting of data, ancillary data and related information. 15 Sep 2024
  34. 34 send() function of python socket class The send() function sends data from one socket to another connected socket. It works on TCP based sockets, both clients and the client-connected sockets at the server side. The Python example code, uses send() in the server program as well as in the client program. 27 Jun 2019
  35. 35 send_fds() function of socket module in Python The send_fds() function sends a list of file descriptors to another process running on the same machine via Unix domain sockets. The Python example client sends two file descriptors through which the server reads the file contents. 18 Nov 2022
  36. 36 sendmsg() method of python socket class The sendmsg() method sends non-ancillary and ancillary data to a destination socket. 16 Sep 2024
  37. 37 sendto() function of python socket class The sendto() function sends data in bytes form from an UDP socket to another UDP socket. The communication is between a client and a server in either direction. The python examples use sendto() in an UDP server and an UDP client. 28 Jun 2019
  38. 38 socket function in Python The socket function returns a socket object based on address family, socket type, selected protocol or returns a socket from the file descriptor passed 1 Feb 2017
  39. 39 socketpair() function of socket module in Python The socketpair() function of socket module returns a pair of sockets that are connected together which supports full duplex communication between them. 21 Nov 2022
  40. 40 UDP - Client and Server example programs in Python UDP client-server examples in Python make use of socket objects created with SOCK_DGRAM and exchange data with sendto(), recvfrom() functions 1 Feb 2017