[Go to site: main page, start]

0% found this document useful (0 votes)
6 views12 pages

Python Socket Programming Basics

The document discusses socket programming in Python. It explains what sockets are, socket vocabulary, how to create sockets using the socket module, common client and server socket methods, general socket methods, and provides a simple example of a TCP client-server program.

Uploaded by

mohamad2000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views12 pages

Python Socket Programming Basics

The document discusses socket programming in Python. It explains what sockets are, socket vocabulary, how to create sockets using the socket module, common client and server socket methods, general socket methods, and provides a simple example of a TCP client-server program.

Uploaded by

mohamad2000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Socket

uModule 2
Programming
with Python
What is socket?

• Sockets are the endpoints of a bidirectional communications


channel.
• Sockets may communicate within a process, between processes
on the same machine, or between processes on different
continents.
2-3

Socket programming

goal: learn how to build client/server applications that communicate using sockets
socket: dropbox between application process and end-end-transport protocol

application application
socket controlled by
process process app developer

transport transport
network network controlled
link by OS
link Internet
physical physical

Application Layer
Socket Vocabulary
The Socket Module

• To create a socket, you must use the [Link]() function available in socket
module, which has the general syntax:

Here is the description of the parameters:

• socket_family: This is either AF_UNIX or AF_INET, as explained earlier.

• socket_type: This is either SOCK_STREAM or SOCK_DGRAM.

• protocol: This is usually left out, defaulting to 0.


Server Socket Methods

Once you have socket object, then you can use required functions
to create your client or server program. Following is the list of
functions required:
Client Socket Methods
General Socket Methods
A Simple TCP
Server
A Simple TCP Client
Running Your TCP Client Server
Program
• Run [Link] at the background, then run [Link]
• The output would be like this:
Summary

• Methods for client and server


• General socket methods
• Running and testing TCP client and server

You might also like