Sokets tutorial

Páginas: 23 (5532 palabras) Publicado: 24 de noviembre de 2011
Linux Howtos: C/C++ -> Sockets Tutorial

http://www.linuxhowtos.org/C_C++/socket.htm

www.LinuxHowtos.org howtos, tips&tricks and tutorials for linux
search for: fulltextsearch search text in: howtos manpages Home News Archive links from external sites Network LDAP Infrared Devices Graphics Gimp creating an analog gauge image OpenGL Programming C/C++ CGI Secure programming Misc VI SystemPCMCIA Security Tips and Tricks Browser plugins Help out Distributions specific Gentoo Fedora contact interesting sites german sites manpages tools FAQ Sitemap You are here: Programming->C/C++ .

Sockets Tutorial
This is a simple tutorial on using sockets for interprocess communication.

The client server model
Most interprocess communication uses the client server model. These terms refer tothe two processes which will be communicating with each other. One of the two processes, the client, connects to the other process, the server, typically to make a request for information. A good analogy is a person who makes a phone call to another person. Notice that the client needs to know of the existence of and the address of the server, but the server does not need to know the address of (oreven the existence of) the client prior to the connection being established. Notice also that once a connection is established, both sides can send and receive information. The system calls for establishing a connection are somewhat different for the client and the server, but both involve the basic construct of a socket. A socket is one end of an interprocess communication channel. The twoprocesses each establish their own socket. The steps involved in establishing a socket on the client side are as follows: 1. Create a socket with the socket() system call 2. Connect the socket to the address of the server using the connect() system call 3. Send and receive data. There are a number of ways to do this, but the simplest is to use the read() and write() system calls. The steps involved inestablishing a socket on the server side are as follows: 1. Create a socket with the socket() system call 2. Bind the socket to an address using the bind() system call. For a server socket on the Internet, an address consists of a port number on the host machine. 3. Listen for connections with the listen() system call 4. Accept a connection with the accept() system call. This call typically blocksuntil a client connects with the server. 5. Send and receive data

other Ads Stellenangebote Stellenangebote für Fach- und Führungskräfte
www.nachoben.com

Other free services toURL.org Shorten long URLs to short links like http://tourl.org/2
tourl.org

Other .linuxhowtos.org sites:toolsntoys.linuxhowtos.org gentoo.linuxhowtos.org

Poll Which linux distribution do you use? SuSe FedoraMandrake Gentoo RedHat Debian other vote poll results Last additions:

FeedCollector Combine various newsfeeds to one customized webpage
www.feedcollector.org

Socket Types
When a socket is created, the program has to specify the address domain and the socket type. Two processes can communicate with each other only if their sockets are of the same type and in the same domain. There are twowidely used address domains, the unix domain, in which two processes which share a common file system communicate, and the

Reverse DNS lookup Find out which hostname(s) resolve to a given IP or other hostnames for the server
www.reversednslookup.org

1 de 13

06/01/11 22:55

Linux Howtos: C/C++ -> Sockets Tutorial
using iotop to find disk usage hogs May 25th. 2007: why adblockers are badhttp://www.linuxhowtos.org/C_C++/socket.htm

Internet domain, in which two processes running on any two hosts on the Internet communicate. Each of these has its own address format. The address of a socket in the Unix domain is a character string which is basically an entry in the file system. The address of a socket in the Internet domain consists of the Internet address of the host...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Sokets
  • Tutoriales
  • tutorial
  • Tutorial
  • Tutorial
  • Tutorial
  • Tutoriales
  • Tutorial

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS