Debian Codegraph @

Tests/SocketTest/client.cpp

raw
1 /*
2 $Id: client.cpp,v 1.3 2003/04/22 06:25:02 plasmoid Exp $
3
4 Program to test how well sockets work in ClanLib.
5
6 Author: Mark Robinson Feb 2003
7 */
8
9 #include <ClanLib/core.h>
10 #include <ClanLib/application.h>
11 #include <ClanLib/network.h>
12
13 #include <iostream>
14
15 class SockClient : public CL_ClanApplication
16 {
17 CL_IPAddress *client_ip;
18 CL_Socket *client_socket;
19
20 public:
21 void print_help()
22 {
23 std::cout << "client [-6|-4]" << std::endl;
24 std::cout << "-6 Connect with IPv6" << std::endl;
25 std::cout << "-4 Connect with IPv4(default)" << std::endl;
26 }
27
28 int main(int argv, char** argc)
29 {
30
31 CL_SetupCore::init();
32 CL_SetupNetwork::init();
33
34 std::string message = (std::string)"ping\n";
35
36 if(argv > 1)
37 {
38 if(strncmp(argc[1], "-6", 2) == 0)
39 {
40 client_ip = new CL_IPAddress("::1", "9000");
41 client_socket = new CL_Socket(CL_Socket::tcp, CL_Socket::ipv6);
42 }
43 else if(strncmp(argc[1], "-4", 2) == 0)
44 {
45 client_ip = new CL_IPAddress("127.0.0.1", "9000");
46 client_socket = new CL_Socket(CL_Socket::tcp, CL_Socket::ipv4);
47 }
48 else
49 {
50 print_help();
51 return 0;
52 }
53 }
54 else
55 {
56 client_ip = new CL_IPAddress("127.0.0.1", "9000");
57 client_socket = new CL_Socket(CL_Socket::tcp, CL_Socket::ipv4);
58 }
59
60 client_socket->connect(*client_ip);
61 client_socket->send(message);
62
63 for(int i = 0; i < 5; i++)
64 {
65 CL_System::keep_alive();
66 client_socket->send(message);
67 CL_System::sleep(1000);
68 }
69
70 delete client_ip;
71 delete client_socket;
72
73 return 0;
74
75
76 }
77
78
79 } app;