26 #include <arpa/inet.h>
42 unsigned int tTime, iPcks;
46 cout <<
"got connection from " << inet_ntoa(addr.sin_addr) << endl;
55 cout <<
" Fehler: " << (pNetIO->
GetError() ? pNetIO->
GetError() :
"bla") << endl;
63 if (tNow > tTime + 1000)
65 cout << iPcks <<
" packets in " << tNow - tTime <<
" ms (" << iPcks * 1000 / (tNow - tTime) <<
" per second, " << (iPcks ? (tNow - tTime) * 1000 / iPcks : -1u) <<
"us per packet)" << endl;
74 for (
int i = 0; i <
iCnt; i++)
76 if (!pNetIO->
Send(Dummy))
77 cout <<
" Fehler: " << (pNetIO->
GetError() ? pNetIO->
GetError() :
"bla") << endl;
80 pNetIO->
Send(rPacket);
87 cout <<
"client from " << inet_ntoa(addr.sin_addr) <<
" disconnected (" << szReason <<
")" << endl;
91 cout <<
"network error: " << strError << endl;
95 int main(
int argc,
char * argv[])
112 CBClass.
AddIO(pNetIO);
117 WSAStartup(0x0202, &wsaData);
122 addr.sin_addr.s_addr = inet_addr(
"127.0.0.1");
123 addr.sin_port = htons(11111);
124 addr.sin_family = AF_INET;
127 for (i = 1; i < argc; ++i)
129 std::string arg(argv[i]);
131 if (arg ==
"--server")
134 if (!iPort) iPort = 11111;
136 else if ((n = arg.find(
"--port=")) != -1)
138 std::istringstream stream(std::string(arg.begin() + n +
sizeof(
"--port="), arg.end()));
141 else if ((n = arg.find(
"--size=")) != -1)
143 std::istringstream stream(std::string(arg.begin() + n +
sizeof(
"--size="), arg.end()));
148 if (!ResolveAddress(argv[i], &addr, 11111)) cout <<
"Fehler in ResolveAddress(" << argv[i] <<
")" << std::endl;
149 if (!iPort) iPort = 11112;
155 cout <<
"Possible usage: " << argv[0] <<
" [--server] [address[:port]] --port=port --size=size" << std::endl << std::endl;
158 cout <<
"Server? (j/n)";
162 while (tolower(cChoice) !=
'n' && tolower(cChoice) !=
'j');
164 fHost = (tolower(cChoice) ==
'j');
166 if (cChoice ==
'J' || cChoice ==
'N')
168 iPort = (cChoice ==
'J' ? 11111 : 11112);
185 while (iSize < 1 || iSize > 1024);
193 strcpy(szAddr,
"127.0.0.1");
198 cout <<
"Wohin (Adresse)? ";
201 cout <<
"Wohin (Port)? ";
204 addr.sin_addr.s_addr = inet_addr(szAddr);
205 addr.sin_port = htons(iDPort);
206 addr.sin_family = AF_INET;
209 cout <<
"\nC4NetIO Init...";
211 if (!NetIO.
Init(iPort))
213 cout <<
" Fehler: " << NetIO.
GetError() << endl;
217 cout <<
" ok" << endl;
223 cout <<
" Broadcast...";
227 cout <<
" Fehler: " << NetIO.
GetError() << endl;
231 cout <<
" ok" << endl;
233 cout <<
" Thread...";
235 if (!CBClass.
Start())
237 cout <<
" Fehler!" << endl;
241 cout <<
" ok" << endl;
243 cout <<
"listening... " << endl;
248 cout <<
" Thread...";
250 if (!CBClass.
Start())
252 cout <<
" Fehler!" << endl;
256 cout <<
" ok" << endl;
258 cout <<
"verbinden mit " << inet_ntoa(addr.sin_addr) <<
":" << ntohs(addr.sin_port) <<
"...\n";
265 char *pBuf =
new char [iBufLen];
266 for (
int i = 0; i < 10; i++)
270 cout <<
" Fehler: " << (pNetIO->
GetError() ? pNetIO->
GetError() :
"bla") << endl;
276 while (std::cin.get() == 10);
void FixedRandom(uint64_t seed)
char DummyData[1024 *1024]
int main(int argc, char *argv[])
virtual const char * GetError() const
virtual bool Send(const class C4NetIOPacket &rPacket)=0
void AddIO(C4NetIO *pNetIO, bool fSetCallback=true)
const C4NetIO::addr_t & getAddr() const
uint8_t getStatus() const
bool Connect(const addr_t &addr) override
bool InitBroadcast(addr_t *pBroadcastAddr) override
bool Init(uint16_t iPort=addr_t::IPPORT_NONE) override
static C4TimeMilliseconds Now()
virtual void OnPacket(const class C4NetIOPacket &rPacket, C4NetIO *pNetIO)
virtual bool OnConn(const C4NetIO::addr_t &addr, const C4NetIO::addr_t &addr2, C4NetIO *pNetIO)
virtual void OnError(const char *strError, C4NetIO *pNetIO)
virtual void OnDisconn(const C4NetIO::addr_t &addr, C4NetIO *pNetIO, const char *szReason)