Blame view

JChatClient/doc/latex/client_code.tex 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Ejemplo de aplicaciĆ³n cliente


\begin{DoxyCode}
\textcolor{preprocessor}{#include "\hyperlink{_socket_8h}{Socket.h}"}
\textcolor{preprocessor}{#include <iostream>}
\textcolor{preprocessor}{#include "\hyperlink{_socket_exception_8h}{SocketException.h}"}
\textcolor{preprocessor}{#include <sstream>}
\textcolor{preprocessor}{#include <signal.h>}
\textcolor{preprocessor}{#include <cstdlib>}
\textcolor{preprocessor}{#include <sys/time.h>}

\textcolor{keyword}{using namespace }std;

\textcolor{keywordtype}{void} \hyperlink{client_8cpp_a00a6f7afcba6bb656a7b05c67efa42ba}{exitClient}(\textcolor{keywordtype}{int} signal)
\{
        cout << \textcolor{stringliteral}{"Server connection terminated unexpectedly"} << endl << \textcolor{stringliteral}{"Exiting"} << endl;
        exit(-1);
\}

\textcolor{keywordtype}{int} \hyperlink{client_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4}{main}()
\{
        signal(SIGPIPE, \hyperlink{client_8cpp_a00a6f7afcba6bb656a7b05c67efa42ba}{exitClient});
        signal(SIGINT, \hyperlink{client_8cpp_a00a6f7afcba6bb656a7b05c67efa42ba}{exitClient});
        \hyperlink{class_socket}{Socket} s;
        \textcolor{keywordtype}{string} send, recv, host;
        \textcolor{keywordtype}{int} port;
        s.\hyperlink{class_socket_add736ccf41f102910a2b8ac5e77eb8b1}{Create}();
        cout << \textcolor{stringliteral}{"Created socket"} << endl;
        cout << \textcolor{stringliteral}{"Hostname: "};
        cin >> host;
        cout << \textcolor{stringliteral}{"Port: "};
        cin >> port;
        cin.ignore();
        s.\hyperlink{class_socket_aa1d074c1aa400e8bca7c7da79b036abe}{Connect}(host,port);
        cout << \textcolor{stringliteral}{"Connected"} << endl;
        \textcolor{keywordflow}{while}(\textcolor{keyword}{true})
        \{
                cout << \textcolor{stringliteral}{"> "};
                getline(cin,send);
                s >> recv;
                cout << \textcolor{stringliteral}{"Received: "} << recv << endl;
        \}
\}
\end{DoxyCode}