1rudesocket(3)                    User Manuals                    rudesocket(3)
2
3
4

NAME

6       rudesocket - Library (C++ API) for making Client Socket Connections
7
8

SYNOPSIS

10            #include <rude/socket.h>
11
12           rude::Socket *socket = new Socket();
13           socket->connect('example.com', 80);
14           socket->sends('GET / HTTP/1.00);
15           const char *response = socket->reads();
16           cout << response;
17           socket->close();
18
19   Public Member Functions
20       Socket ()
21           Constructor.
22       ~Socket ()
23           Destructor.
24       void setTimeout (int seconds, int microseconds)
25           Sets the timeout value for Connect, Read and Send operations.
26       const char * getError ()
27           Returns a description of the last known error.
28       bool connect (const char *server, int port)
29           Connects to the specified server and port.
30       bool connectSSL (const char *server, int port)
31           Connects to the specified server and port over a secure connection.
32       bool insertTunnel (const char *server, int port)
33           Inserts a transparent tunnel into the connect chain.
34       bool  insertSocks5 (const char *server, int port, const char *username,
35           const char *password)
36           Inserts a Socks5 server into the connect chain.
37       bool insertSocks4 (const char *server, int port, const char *username)
38           Inserts a Socks4 server into the connect chain.
39       bool insertProxy (const char *server, int port)
40           Inserts a CONNECT-Enabled HTTP proxy into the connect chain.
41       int send (const char *data, int length)
42           Sends a buffer of data over the connection.
43       int read (char *buffer, int length)
44           Reads a buffer of data from the connection.
45       const char * reads ()
46           Reads everything available from the connection.
47       const char * readline ()
48           Reads a line from the connection.
49       bool sends (const char *buffer)
50           Sends a null terminated string over the connection.
51       bool close ()
52           Closes the connection.
53       void setMessageStream (std::ostream &o)
54           Sets an output stream  to  receive  real-time  messages  about  the
55           socket.
56

Detailed Description

58       The public interface to the Socket component.
59
60       If  you  are  using  windows, you will need to initiate the winsock DLL
61       yourself, and finish the DLL yourself when you are done using the  com‐
62       ponent.
63

General Usage

65           Socket *socket = new Socket();
66           socket->connect('example.com', 80);
67           socket->sends('GET / HTTP/1.00);
68           const char *response = socket->reads();
69           cout << response;
70           socket->close();
71

SSL Usage

73           Socket *socket = new Socket();
74           socket->connectSSL('example.com', 443);
75           socket->sends('GET / HTTP/1.00);
76           const char *response = socket->reads();
77           cout << response;
78           socket->close();
79

Chaining Connections

81           Socket *socket = new Socket();
82           socket->insertSocks4('12.34.56.78', 8000, 'username');
83           socket->insertSocks5('12.34.56.78', 8000, 'username', 'password');
84           socket->insertProxy('12.34.56.78', 8080);
85           socket->connectSSL('example.com', 443);
86           socket->sends('GET / HTTP/1.00);
87           const char *response = socket->reads();
88           cout << response;
89           socket->close();
90

Adding Error checking

92           Socket *socket = new Socket();
93           if(socket->connectSSL('google.com', 443))
94           {
95               if(socket->sends('GET / HTTP/1.00))
96               {
97                   const char *response = socket->reads();
98                   if(response)
99                   {
100                       cout << response;
101                   }
102                   else
103                   {
104                       cout << socket->getError() << '0;
105                   }
106               }
107               else
108               {
109                   cout << socket->getError() << '0;
110               }
111               socket->close();
112           }
113           else
114           {
115               cout << socket->getError() << '0;
116           }
117

Constructor & Destructor Documentation

119   rude::Socket::Socket ()
120       Constructor.
121
122   rude::Socket::~Socket ()
123       Destructor.
124

Member Function Documentation

126   bool rude::Socket::close ()
127       Closes the connection.
128
129       A connection must established before this method can be called
130
131   bool rude::Socket::connect (const char * server, int port)
132       Connects to the specified server and port.
133
134       If  proxies  have  been  specified,  the  connection passes through tem
135       first.
136
137   bool rude::Socket::connectSSL (const char * server, int port)
138       Connects to the specified server and port over a secure connection.
139
140       If proxies have been specified,  the  connection  passes  through  them
141       first.
142
143   const char* rude::Socket::getError ()
144       Returns a description of the last known error.
145
146   bool rude::Socket::insertProxy (const char * server, int port)
147       Inserts a CONNECT-Enabled HTTP proxy into the connect chain.
148
149       Becomes  the last server connected to in the chain before connecting to
150       the destination server
151
152   bool rude::Socket::insertSocks4 (const char * server, int port, const  char
153       * username)
154       Inserts a Socks4 server into the connect chain.
155
156       Becomes  the last server connected to in the chain before connecting to
157       the destination server
158
159   bool rude::Socket::insertSocks5 (const char * server, int port, const  char
160       * username, const char * password)
161       Inserts a Socks5 server into the connect chain.
162
163       Becomes  the last server connected to in the chain before connecting to
164       the destination server
165
166   bool rude::Socket::insertTunnel (const char * server, int port)
167       Inserts a transparent tunnel into the connect chain.
168
169       A transparent Tunnel is a server that accepts a connection on a certain
170       port,  and  always  connects to a particular server:port address on the
171       other side. Becomes the last server connected to in  the  chain  before
172       connecting to the destination server
173
174   int rude::Socket::read (char * buffer, int length)
175       Reads a buffer of data from the connection.
176
177       A connection must established before this method can be called
178
179   const char* rude::Socket::readline ()
180       Reads a line from the connection.
181
182       A connection must established before this method can be called
183
184   const char* rude::Socket::reads ()
185       Reads everything available from the connection.
186
187       A connection must established before this method can be called
188
189   int rude::Socket::send (const char * data, int length)
190       Sends a buffer of data over the connection.
191
192       A connection must established before this method can be called
193
194   bool rude::Socket::sends (const char * buffer)
195       Sends a null terminated string over the connection.
196
197       The  string  can  contain its own newline characters. Returns false and
198       sets the error message if it fails to send the line. A connection  must
199       established before this method can be called
200
201   void rude::Socket::setMessageStream (std::ostream & o)
202       Sets an output stream to receive real-time messages about the socket.
203
204   void rude::Socket::setTimeout (int seconds, int microseconds)
205       Sets the timeout value for Connect, Read and Send operations.
206
207       Setting the timeout to 0 removes the timeout - making the Socket block‐
208       ing.
209
210

SEE ALSO

212       rudecgiparser(3), rudeconfig(3), rudedatabase(3), rudesession(3)
213
214

REPORTING PROBLEMS

216       Before reporting a problem, please check the rudeserver.com web site to
217       verify  that  you  have  the  latest  version of rudesocket; otherwise,
218       obtain the latest version and see if the problem still exists.   Please
219       read the  FAQ at:
220
221                     http://www.rudeserver.com/
222
223       before  asking for help.  Send questions and/or comments to  matt@rude‐
224       server.com
225
226

AUTHORS

228       Copyright (C) 2000-2008 Matthew Flood (matt@rudeserver.com)
229
230       This  software is provided "as-is," without any express or implied war‐
231       ranty.   In  no  event  will the authors be held liable for any damages
232       arising from the use of this software.  See the distribution  directory
233       with  respect   to   requirements  governing  redistribution. Thanks to
234       all the people who reported problems and suggested various improvements
235       in rudesocket; who are too numerous to cite here.
236
237
238
239
240Version 1.1.0                     15 Jan 2008                    rudesocket(3)
Impressum