|A little network programming with example code.|
A socket is a connection from a process to another process. The two processes are typically on different machines, but they can also be on the same machine.Update April 4, 2005: Librenix is now featuring a Linux multithreaded Socket programming game server project in C. The Space Tyrant design is covered here and the first Space Tyrant code release is discussed here.
The most common use of a socket is to connect a client with a server, similar to placing a phone call to some phone service. The client creates a socket (picks up the phone), then connects it to the server (dials the phone, waits for an answer).
Once the sockets are connected, communication is generally bi-directional, using some agreed-upon protocol. You must have a protocol to know who is talking at any given time, and what it means. For example, the HyperText Transfer Protocol (HTTP) defines how to get a Web page, including defining precisely each side's role in the conversation. Simple Mail Transfer Protocol (SMTP) defines the transmission of email, and so on. When the connection is finished, both sides hang up.
To Perl, a socket is presented as a filehandle...