class_socket.tex 12.9 KB
\hypertarget{class_socket}{\section{Referencia de la Clase Socket}
\label{class_socket}\index{Socket@{Socket}}
}


Clase del socket.  




{\ttfamily \#include $<$Socket.\-h$>$}

\subsection*{Métodos públicos}
\begin{DoxyCompactItemize}
\item 
\hyperlink{class_socket_a7c3256c4fc6e2c603df73201049fae5a}{Socket} ()
\begin{DoxyCompactList}\small\item\em Constructor de la clase \hyperlink{class_socket}{Socket}. \end{DoxyCompactList}\item 
void \hyperlink{class_socket_add736ccf41f102910a2b8ac5e77eb8b1}{Create} ()
\begin{DoxyCompactList}\small\item\em Método para crear sockets. \end{DoxyCompactList}\item 
void \hyperlink{class_socket_afdc52c70cf11911cc1a3c595a7849cf0}{Bind} (string address, int port)
\begin{DoxyCompactList}\small\item\em Método para hacer bind a una dirección y puerto. \end{DoxyCompactList}\item 
void \hyperlink{class_socket_a4d476d11854d7acb17b8d196c8171865}{Listen} (int backlog)
\begin{DoxyCompactList}\small\item\em Método para escuchar conexiones. \end{DoxyCompactList}\item 
void \hyperlink{class_socket_a25cdd79546b8e7e49f2195208ae6d00c}{Accept} (\hyperlink{class_socket}{Socket} \&client\-Sock)
\begin{DoxyCompactList}\small\item\em Método para aceptar conexiones. \end{DoxyCompactList}\item 
void \hyperlink{class_socket_aa1d074c1aa400e8bca7c7da79b036abe}{Connect} (string hostname, int port)
\begin{DoxyCompactList}\small\item\em Método para efectuar conexiones. \end{DoxyCompactList}\item 
void \hyperlink{class_socket_a4c8ced9a8ce58834191b3b4f2033b173}{Close} ()
\begin{DoxyCompactList}\small\item\em Método para cerrar sockets. \end{DoxyCompactList}\item 
int \hyperlink{class_socket_abc14da0faa1d00fe361eeede1b3cda4a}{get\-Sock} ()
\begin{DoxyCompactList}\small\item\em Getter para el file descriptor del socket. \end{DoxyCompactList}\item 
const \hyperlink{class_socket}{Socket} \& \hyperlink{class_socket_a5beab0c84c933510a53126f786cff6de}{operator$<$$<$} (const string \&)
\begin{DoxyCompactList}\small\item\em Método para enviar mensajes. \end{DoxyCompactList}\item 
const \hyperlink{class_socket}{Socket} \& \hyperlink{class_socket_ab6b2dffea36c60c53f8d5e539f1cf000}{operator$>$$>$} (string \&)
\begin{DoxyCompactList}\small\item\em Método para recibir mensajes. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Métodos privados}
\begin{DoxyCompactItemize}
\item 
int \hyperlink{class_socket_aa1a8b143bb2adf57934156d9e33b8611}{Receive} (char $\ast$buff, int length)
\begin{DoxyCompactList}\small\item\em Método para recibir un mensaje de longitud conocida. \end{DoxyCompactList}\item 
int \hyperlink{class_socket_a4c4ecb88d5587177899198861d29d3dd}{Send} (const char $\ast$buff, int length)
\begin{DoxyCompactList}\small\item\em Método para enviar un mensaje de longitud conocida. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Atributos privados}
\begin{DoxyCompactItemize}
\item 
int \hyperlink{class_socket_a231ddf6e338a86640e26808b83efeaa1}{sock}
\begin{DoxyCompactList}\small\item\em Descriptor del fichero del socket. \end{DoxyCompactList}\item 
struct sockaddr\-\_\-in \hyperlink{class_socket_ae4d80b83c327ed835b5f4575a499a400}{sock\-Addr}
\begin{DoxyCompactList}\small\item\em Estructura de dirección de socket. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Descripción detallada}
Clase del socket. 

Esta clase define un objeto con los métodos y atributos necesarios para realizar comunicación encriptada o en texto llano a través de un socket T\-C\-P/\-I\-P en un entorno U\-N\-I\-X abstrayendo la implementación de sockets y de encriptación al programador. 

\subsection{Documentación del constructor y destructor}
\hypertarget{class_socket_a7c3256c4fc6e2c603df73201049fae5a}{\index{Socket@{Socket}!Socket@{Socket}}
\index{Socket@{Socket}!Socket@{Socket}}
\subsubsection[{Socket}]{\setlength{\rightskip}{0pt plus 5cm}Socket\-::\-Socket (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}\label{class_socket_a7c3256c4fc6e2c603df73201049fae5a}


Constructor de la clase \hyperlink{class_socket}{Socket}. 

Inicializa el file descriptor del socket y prepara la memoria donde se almacenarán las llaves públicas. 

\subsection{Documentación de las funciones miembro}
\hypertarget{class_socket_a25cdd79546b8e7e49f2195208ae6d00c}{\index{Socket@{Socket}!Accept@{Accept}}
\index{Accept@{Accept}!Socket@{Socket}}
\subsubsection[{Accept}]{\setlength{\rightskip}{0pt plus 5cm}void Socket\-::\-Accept (
\begin{DoxyParamCaption}
\item[{{\bf Socket} \&}]{client\-Sock}
\end{DoxyParamCaption}
)}}\label{class_socket_a25cdd79546b8e7e49f2195208ae6d00c}


Método para aceptar conexiones. 

Este método bloquea el thread que lo ejecuta hasta que recibe una conexión entrante, que almacena como instancia de la clase \hyperlink{class_socket}{Socket} en la referencia proporcionada por argumento. 
\begin{DoxyParams}{Parámetros}
{\em client\-Sock} & Instáncia de \hyperlink{class_socket}{Socket} que comunica con el cliente entrante \\
\hline
\end{DoxyParams}
\hypertarget{class_socket_afdc52c70cf11911cc1a3c595a7849cf0}{\index{Socket@{Socket}!Bind@{Bind}}
\index{Bind@{Bind}!Socket@{Socket}}
\subsubsection[{Bind}]{\setlength{\rightskip}{0pt plus 5cm}void Socket\-::\-Bind (
\begin{DoxyParamCaption}
\item[{string}]{address, }
\item[{int}]{port}
\end{DoxyParamCaption}
)}}\label{class_socket_afdc52c70cf11911cc1a3c595a7849cf0}


Método para hacer bind a una dirección y puerto. 

Este método asigna el socket a una dirección I\-P (y por tanto, a una interfaz de red en concreto) y un puerto, para que posteriormente actúe de servidor escuchando conexiones. 
\begin{DoxyParams}{Parámetros}
{\em address} & Dirección I\-P asignada \\
\hline
{\em port} & Puerto asignado \\
\hline
\end{DoxyParams}
\hypertarget{class_socket_a4c8ced9a8ce58834191b3b4f2033b173}{\index{Socket@{Socket}!Close@{Close}}
\index{Close@{Close}!Socket@{Socket}}
\subsubsection[{Close}]{\setlength{\rightskip}{0pt plus 5cm}void Socket\-::\-Close (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}\label{class_socket_a4c8ced9a8ce58834191b3b4f2033b173}


Método para cerrar sockets. 

Este método cierra el socket para que no se pueda escribir ni leer más en él, para liberarlo del kernel y terminar la conexión T\-C\-P. \hypertarget{class_socket_aa1d074c1aa400e8bca7c7da79b036abe}{\index{Socket@{Socket}!Connect@{Connect}}
\index{Connect@{Connect}!Socket@{Socket}}
\subsubsection[{Connect}]{\setlength{\rightskip}{0pt plus 5cm}void Socket\-::\-Connect (
\begin{DoxyParamCaption}
\item[{string}]{hostname, }
\item[{int}]{port}
\end{DoxyParamCaption}
)}}\label{class_socket_aa1d074c1aa400e8bca7c7da79b036abe}


Método para efectuar conexiones. 

Este método sirve a los sockets que actúan como cliente para poder efectuar conexiones a otro socket que esté escuchando en la dirección y puerto especificados y atienda conexiones. 
\begin{DoxyParams}{Parámetros}
{\em hostname} & Hostname al que conectarse \\
\hline
{\em port} & Puerto al que conectarse \\
\hline
\end{DoxyParams}
\hypertarget{class_socket_add736ccf41f102910a2b8ac5e77eb8b1}{\index{Socket@{Socket}!Create@{Create}}
\index{Create@{Create}!Socket@{Socket}}
\subsubsection[{Create}]{\setlength{\rightskip}{0pt plus 5cm}void Socket\-::\-Create (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}\label{class_socket_add736ccf41f102910a2b8ac5e77eb8b1}


Método para crear sockets. 

Crea un file descriptor para un socket que por defecto no está conectado ni asignado a ninguna dirección. \hypertarget{class_socket_abc14da0faa1d00fe361eeede1b3cda4a}{\index{Socket@{Socket}!get\-Sock@{get\-Sock}}
\index{get\-Sock@{get\-Sock}!Socket@{Socket}}
\subsubsection[{get\-Sock}]{\setlength{\rightskip}{0pt plus 5cm}int Socket\-::get\-Sock (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}\label{class_socket_abc14da0faa1d00fe361eeede1b3cda4a}


Getter para el file descriptor del socket. 

Este método devuelve el file descriptor del socket. \hypertarget{class_socket_a4d476d11854d7acb17b8d196c8171865}{\index{Socket@{Socket}!Listen@{Listen}}
\index{Listen@{Listen}!Socket@{Socket}}
\subsubsection[{Listen}]{\setlength{\rightskip}{0pt plus 5cm}void Socket\-::\-Listen (
\begin{DoxyParamCaption}
\item[{int}]{backlog}
\end{DoxyParamCaption}
)}}\label{class_socket_a4d476d11854d7acb17b8d196c8171865}


Método para escuchar conexiones. 

Este método configura el socket para que se ponga en modo escucha y así pueda atender conexiones entrantes. 
\begin{DoxyParams}{Parámetros}
{\em backlog} & Número máximo de conexiones {\bfseries en espera} \\
\hline
\end{DoxyParams}
\hypertarget{class_socket_a5beab0c84c933510a53126f786cff6de}{\index{Socket@{Socket}!operator$<$$<$@{operator$<$$<$}}
\index{operator$<$$<$@{operator$<$$<$}!Socket@{Socket}}
\subsubsection[{operator$<$$<$}]{\setlength{\rightskip}{0pt plus 5cm}const {\bf Socket} \& Socket\-::operator$<$$<$ (
\begin{DoxyParamCaption}
\item[{const string \&}]{text}
\end{DoxyParamCaption}
)}}\label{class_socket_a5beab0c84c933510a53126f786cff6de}


Método para enviar mensajes. 

Este método envía el mensaje que se le proporciona a través del \hyperlink{class_socket}{Socket} con o sin encriptación según las \hyperlink{howto_defines}{opciones de compilación} usando el \hyperlink{howto_proto}{protocolo} implementado. 
\begin{DoxyParams}{Parámetros}
{\em text} & Mensaje a enviar \\
\hline
\end{DoxyParams}
\hypertarget{class_socket_ab6b2dffea36c60c53f8d5e539f1cf000}{\index{Socket@{Socket}!operator$>$$>$@{operator$>$$>$}}
\index{operator$>$$>$@{operator$>$$>$}!Socket@{Socket}}
\subsubsection[{operator$>$$>$}]{\setlength{\rightskip}{0pt plus 5cm}const {\bf Socket} \& Socket\-::operator$>$$>$ (
\begin{DoxyParamCaption}
\item[{std\-::string \&}]{text}
\end{DoxyParamCaption}
)}}\label{class_socket_ab6b2dffea36c60c53f8d5e539f1cf000}


Método para recibir mensajes. 

Este método recibe un mensaje de longitud arbitrária con o sin encriptación según las \hyperlink{howto_defines}{opciones de compilación} usando el \hyperlink{howto_proto}{protocolo} implementado. 
\begin{DoxyParams}{Parámetros}
{\em text} & Mensaje a recibir \\
\hline
\end{DoxyParams}
\hypertarget{class_socket_aa1a8b143bb2adf57934156d9e33b8611}{\index{Socket@{Socket}!Receive@{Receive}}
\index{Receive@{Receive}!Socket@{Socket}}
\subsubsection[{Receive}]{\setlength{\rightskip}{0pt plus 5cm}int Socket\-::\-Receive (
\begin{DoxyParamCaption}
\item[{char $\ast$}]{buff, }
\item[{int}]{length}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [private]}}}\label{class_socket_aa1a8b143bb2adf57934156d9e33b8611}


Método para recibir un mensaje de longitud conocida. 

Este método se usa para recibir un mensaje de la longitud que se especifica por argumento y almacenarlo en el buffer proporcionado.

{\itshape Este método garantiza que todo el mensaje se recibirá entero aunque la red no admita una longitud de paquete tan grande.} 
\begin{DoxyParams}{Parámetros}
{\em buff} & Buffer donde se almacena el mensaje recibido \\
\hline
{\em length} & Longitud del mensaje a recibir \\
\hline
\end{DoxyParams}
\hypertarget{class_socket_a4c4ecb88d5587177899198861d29d3dd}{\index{Socket@{Socket}!Send@{Send}}
\index{Send@{Send}!Socket@{Socket}}
\subsubsection[{Send}]{\setlength{\rightskip}{0pt plus 5cm}int Socket\-::\-Send (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{buff, }
\item[{int}]{length}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [private]}}}\label{class_socket_a4c4ecb88d5587177899198861d29d3dd}


Método para enviar un mensaje de longitud conocida. 

Este método se usa para enviar un mensaje de la longitud especifidada en el argumento y devuelve el número de bytes enviados.

{\itshape Este método garantiza que todo el mensaje se enviará entero aunque la red no admita una longitud de paquete tan grande.} 
\begin{DoxyParams}{Parámetros}
{\em buff} & Buffer con el mensaje a enviar \\
\hline
{\em length} & Longitud del mensaje \\
\hline
\end{DoxyParams}


\subsection{Documentación de los datos miembro}
\hypertarget{class_socket_a231ddf6e338a86640e26808b83efeaa1}{\index{Socket@{Socket}!sock@{sock}}
\index{sock@{sock}!Socket@{Socket}}
\subsubsection[{sock}]{\setlength{\rightskip}{0pt plus 5cm}int Socket\-::sock\hspace{0.3cm}{\ttfamily [private]}}}\label{class_socket_a231ddf6e338a86640e26808b83efeaa1}


Descriptor del fichero del socket. 

Esta variable contiene el file descriptor del socket abierto por el S\-O. \hypertarget{class_socket_ae4d80b83c327ed835b5f4575a499a400}{\index{Socket@{Socket}!sock\-Addr@{sock\-Addr}}
\index{sock\-Addr@{sock\-Addr}!Socket@{Socket}}
\subsubsection[{sock\-Addr}]{\setlength{\rightskip}{0pt plus 5cm}struct sockaddr\-\_\-in Socket\-::sock\-Addr\hspace{0.3cm}{\ttfamily [private]}}}\label{class_socket_ae4d80b83c327ed835b5f4575a499a400}


Estructura de dirección de socket. 

Este struct es usado por el S\-O para gestionar la dirección del socket abierto. 

La documentación para esta clase fue generada a partir de los siguientes ficheros\-:\begin{DoxyCompactItemize}
\item 
/home/imanol/devel/eclipse/\-P\-A\-D/\-J\-Chat\-Client/src/include/\hyperlink{_socket_8h}{Socket.\-h}\item 
/home/imanol/devel/eclipse/\-P\-A\-D/\-J\-Chat\-Client/src/\hyperlink{_socket_8cpp}{Socket.\-cpp}\end{DoxyCompactItemize}