Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/subprojects/network/network_unit_test.cc @ 5627

Last change on this file since 5627 was 5627, checked in by hdavid, 18 years ago

fixed network_socket.cc

File size: 2.3 KB
Line 
1
2#include "stdlibincl.h"
3#include <stdarg.h>
4#include <stdio.h>
5#include "shell_buffer.h"
6#include "class_list.h"
7
8#include "network_manager.h"
9#include "network_socket.h"
10
11int verbose = 4;
12
13
14int startHelp(int argc, char** argv)
15{
16  printf("Network is a network unit test\n");
17  printf(" --help:           this output\n");
18  printf(" --sockettest      test network_socket\n");
19  printf("\n");
20}
21
22int testSocket(int argc, char** argv)
23{
24  NetworkSocket client;
25  NetworkSocket server;
26  IPaddress ip;
27  SDLNet_ResolveHost(&ip, "127.0.0.1", 9999);
28  server.listen(9999);
29  client.connectToServer(ip, 9999);
30  char buf[1024];
31
32  printf("read from client before sending data\n");
33  printf("result: %d bytes\n", client.readBytes((byte*)buf, 1024));
34
35  printf("read from server before sending data\n");
36  printf("result: %d bytes\n", server.readBytes((byte*)buf, 1024));
37
38  int n;
39        char * str1 = "client to server";
40  char * str2 = "server to client";
41  n = client.writeBytes((byte*)str1, strlen(str1)+1);
42        printf("%d bytes send from client\n", n);
43  n = server.writeBytes((byte*)str2, strlen(str2)+1);
44        printf("%d bytes send from server\n", n);
45  SDL_Delay(1000);
46 
47  printf("read from server\n");
48  n = server.readBytes((byte*)buf, 1024);
49  printf("read %d bytes\n", n);
50  if (n<0)
51    return -1;
52
53  printf("data: %s\n", buf);
54  printf("read from client\n");
55  n = client.readBytes((byte*)buf, 1024);
56
57  printf("read %d bytes\n", n);
58  if (n<0)
59    return -1;
60
61  printf("data: %s\n", buf);
62
63  return 0;
64}
65
66/**
67 *
68 *  main function
69 *
70 * here the journey begins
71 */
72int main(int argc, char** argv)
73{
74  // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
75  int i;
76  for(i = 1; i < argc; ++i)
77  {
78    if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
79    //else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
80    else if (! strcmp( "--sockettest", argv[i]) || !strcmp("-s", argv[i])) return testSocket(argc, argv);
81  }
82
83  /* create the network manager */
84  NetworkManager* nm = new NetworkManager();
85
86  /* initialize the network manager */
87  nm->initialize();
88
89  /* esatblish a connection */
90  nm->establishConnection();
91
92  //ClassList::debug(3, 0);
93
94  return 0;
95}
96
97
98bool ShellBuffer::addBufferLineStatic(const char* line, ...)
99{
100  va_list arguments;
101  vprintf(line, arguments);
102
103}
Note: See TracBrowser for help on using the repository browser.