Home  +  Forums  +  C++ and Sockets  +  C++ and SQL: MySQL, sqlite, ODBC  +  Miscellaneous Projects
Logo
~Sockets~
~New~
~Examples~
~Contact~

C++ Sockets Library

Programación básica de Sockets en Unix / Windows

Esta es una libreria de clases en C++ bajo licencia GPL que 'mapea' el berkeley sockets C API, y funciona tanto en algunos sistemas unix como en win32. Las características incluidas, aunque no limitadas son: SSL support, IPv6 support, tcp and udp sockets, encrypted tcp, http protocol, altamente configurable el manejo de errores. Las pruebas de Testeo han sido efectuadas en: Linux and Windows 2000, and to some part on Solaris and Mac OS X.

Examples   httpget | chat | client/server | mud | proxy | smtp proxy | httpd | chat 2 | udp | icmp

Únete a nuestra comunidad. Para estar enterado de los ultimos cambios y modificaciones a la C++ sockets library, puedes suscribirte en el proyecto en C++ sockets library freshmeat.net project page. Si estas utilizando la C++ sockets library, o tienes alguna pregunta o sugerencia, visita este enlace C++ sockets library message board.

Esta libreria está disponible para *BSD-Ports system for the Darwin OS. Aqui tienes el enlace.

Tambien está disponible a través de la FreeBSD Ports Collection. Por Aquí.

Un poco de historia

Cuando construí esta libreria, hubo cosas que quise tener en cuenta. No queria terminar la cosa del codigo en C++ que tuviese que ser usado de la misma manera que el berkeley socket C API normalmente( connect/bind/accept - check result, write - check result, read - check result, etc, etc ). Otra cosa era tener la capacidad de manejar multiples Socket's en el mismo Thread (Hilo de ejecución); La librería debería ser singlethreaded - pero no limitada a un solo Thread. Asi que.. No queria hacer un fd_set para un select() y volver a llamarlo de nuevo, se acabó el escribir código para aceptar una conexión - Esto lo he conseguido una y otra vez con cada proyecto de trabajo en red con el que he trabajado.

Una decisión temprana, fue trabajar con que cada socket individual...fuese tratado como objeto individual. y asi fue como nació la clase Socket. La clase Socket, en si misma, tiene todas las funciones necesarias para la resolución de direcciones (hostname to ip, ip to hostname etc). Es propietaria del descriptor de fichero/ SOCKET handle. Pero no puede hacer nada mas. El código para poder hacer otras cosas con ella, esta en las clases Socket derivadas.

Tomemos como ejemplo; una lista de sockets activos monitorizados por una llamada al sistema mediante select() . Los eventos resultantes de la llamada a select() y la logica de transmisión (read/write/connect/timeout etc) son reportados a cada socket, por medio de un callback del tipo:

  •   Socket::OnRead()
  •   Socket::OnWrite()
  •   Socket::OnConnect()
  •   Socket::OnAccept()

La lista de sockets utilizados, se encuentra en la clase SocketHandler. para "monitorear" los sockets, se efectuarán una serie de llamadas al método Select().

Ultima version

====> Descargate Sockets-1.7.3.tar.gz, actualizado con fecha 2005-01-24 ( Changelog )

Win32 static libraries (vs6 binaries are compiled as Multithreaded Debug & Release)
Sockets-1.7.3-binaries-vs6.zip, updated 2005-01-24
(vs.net binaries are compiled as Singlethreaded Debug & Release)
Sockets-1.7.3-binaries-vs.net.zip, updated 2005-01-24

Nota! Los binarios de Win32 han sido construidos con stlport. Until i build these with stlport disabled, find more information on obtaining and installing stlport here.

Source code documentation (generated by Doxygen). Selecciona "File List" de la página de índices de Doxigen para ver todos los archivos del ejemplo. Luego selecciona "[code]" para ver el código fuente de ese archivo. Los archivos con el nombre en minúsculas suelen ser el punto de inicio, y los archivos con las letras mayúsculas son la implementacion de la clase del mismo nombre que el archivo..

Diagrama de la Clase & Documentación

Cambios

1.7.3: Applied some of the FreeBSD ports patches. Cleanup up some signed/unsigned warnings. Added test projects (sockets_test.cpp) for visual studio 6 and .net. Added project files and binaries for visual studio .net.

1.7.2: HttpsGetSocket::url_this default port changed to 443 (was 80). TcpSocket buffer sizes adjusted. Switched off LineProtocol when reading the http body in HTTPSocket and HttpsSocket.

1.7.1: CygWin fixes

1.7: Connection pooling added, enabling HTTP/1.1 keep-alive operation. HttpPostSocket supports both urlencoded and multipart posts.

1.6.4: Socket.GetPort, tutorial updated.

1.6.3: Added new classes: HttpPutSocket, HttpPostSocket and HttpDebugSocket. Error logging in windows fixed.

1.6.2: Code cleanup. One bugfix in ListenSocket, when opening a random port GetPort() returned wrong port number - this is now fixed. Removed a lot of #define's for ipv4/ipv6 methods. Methods are now suffixed with a "6" for the ipv6 variant.

1.6.1: Added dummy copy constructor and assignment operator to classes that couldn't be copied by default. Many thanks to q for all suggestions and bug squashing!

1.6: Made use of openssl optional. Win32 compile and link fixes. Bugfixes in buffering, memory leaks fixed, error logging improved and a general code cleanup. Speed optimizations.

1.5.4: Added small fixes and multicast functions to UdpSocket after user suggestions and contributions.

1.5.3: Removed resolve of local hostname from SocketHandler constructor. Replaced read/write in TcpSocket on unix systems to recv/send with flag MSG_NOSIGNAL to avoid sigpipe.

1.5.2: Added some #ifdef's for those of us unfortunate enough to have an operating system without IPv6 support.

1.5.1: Updated UDPSocket, UDP Example (example 9), tutorial updated with udp examples

1.5: C++ Socket library now supports IPv6, Mac OS X compiles ok, OnConnectFailed callback added

1.4: Added error logging, code cleanup. Tutorial updated with source code download

1.3.1: Thread support now working a little bit better (Detach() / OnDetached() ). Example 7 shows a "small" httpd using the new thread code - work in progress.

1.3: Tentative pthread support. No win32 threading yet. Also, check out the new tutorial here.

1.2.2: For all you win32 users out there. I made new visual studio project files for "Sockets.lib" and "SocketsEx.lib", made sure the code compiles, and a binary release (1.2.1).

1.2.1: Made a split into two libraries. "libSockets" contains all classes except Uid, MinionSocket and Minder classes. Those got their own library, "libSocketsEx", because it's a specialization only used by the minder application and minion implementations.

1.2: Added minder/minion framework classes (MinderHandler, MinderSocket, MinionSocket).
TcpSocket got a new callback OnRawData() to bypass input buffering.

Older versions

Download Sockets-1.7.2.tar.gz, updated 2005-01-22
Win32 static libraries (Release, Multithreaded; not tested) Sockets-1.7.zip, updated 2004-11-03
Download Sockets-1.7.1.tar.gz, updated 2004-11-14
Download Sockets-1.7.tar.gz, updated 2004-11-03
Download Sockets-1.6.4.tar.gz, updated 2004-10-31
Win32 static libraries (Release, Multithreaded; not tested) Sockets-1.6.3.zip, updated 2004-10-30
Download Sockets-1.6.3.tar.gz, updated 2004-10-30
Download Sockets-1.6.2.tar.gz, updated 2004-09-27
Win32 static libraries (Release, Multithreaded; not tested) Sockets-1.6.zip
Download Sockets-1.6.1.tar.gz, updated 2004-09-06
Download Sockets-1.6.tar.gz, updated 2004-08-17
Download Sockets-1.5.4.tar.gz, updated 2004-08-02
Win32 static libraries (Release, Multithreaded; not tested) Sockets-1.5.3.zip
Download Sockets-1.5.3.tar.gz, updated 2004-07-12
Download Sockets-1.5.2.tar.gz, updated 2004-06-28
Download Sockets-1.5.tar.gz, updated 2004-06-25
Download Sockets-1.4.tar.gz, updated 2004-06-01
Download Sockets-1.3.1.tar.gz
Download Sockets-1.3.tar.gz
Download Sockets-1.2.2.tar.gz
Download Sockets-1.2.1.tar.gz
Win32 static libraries (Release, Multithreaded; not tested) Sockets-1.2.1.zip
Download Sockets-1.2.tar.gz
Download Sockets-1.1.tar.gz
Download Sockets-1.0.1.tar.gz
Download Sockets-1.0.tar.gz

Dependencies

Projects using C++ Sockets

Links


Page, code, and content Copyright (C) 2009 by Anders Hedström