Home arrow Python arrow Sockets in Python

Sockets in Python

Sockets are the lead pipes of computer networks: they let you connect with other devices so that information can flow freely. As you might expect, they're widely used on the Internet. Peyton McCullough explains how to code sockets in Python.

TABLE OF CONTENTS:
  1. Sockets in Python
  2. The Basics
  3. Connecting to the Server
  4. Sockets...Simplified
  5. Summary
By: Peyton McCullough
Rating: starstarstarstarstar / 113
December 28, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

One of the must-know features of any language is sockets, and, no, Iím not talking about the ones positioned on your ceiling. While many novice scripters will run away at the sound of the word, sockets in Python are not hard to learn and work with at all. In this article, I will explain the basics and even apply sockets in a real-world situation.

Please note that this article assumes that you have a basic command of the Python language. If not, you can either read the official tutorial or buy a book Ė or both. If youíre looking for a good book, you should head over to OíReilly & Associates.

With that stated, letís get started.

The Anatomy of a Socket

Letís start off simple: what is a socket? The easiest way to learn is to compare computer sockets to lead pipes. Letís say you have some sort of machine that has two pipes. One pipe pumps in water and the other pipe pumps out water. This will be your server. Now, imagine you have a simple box that has one pipe going through it. Letís say that you hook it up to your pump machine. It will receive the water from the machine and then give water back. This will be your client. If you wanted to, you could hook up more machines and pipes to this to form a network of clients and servers.

Sockets are useful. The Web browser that you are viewing this page with is connecting to the server that this page is in by way of a socket. If you were to connect to one of your favorite online games or chat networks, you would be using sockets as well. As you can see, sockets are both both powerful and widely-used.



 
 
>>> More Python Articles          >>> More By Peyton McCullough
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: