MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / main

Function main

test/clsocket/EchoServer.cpp:6–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#define MAX_PACKET 4096
5
6int main(int argc, char **argv)
7{
8 CPassiveSocket socket;
9 CActiveSocket *pClient = NULL;
10
11 //--------------------------------------------------------------------------
12 // Initialize our socket object
13 //--------------------------------------------------------------------------
14 socket.Initialize();
15
16 socket.Listen("localhost", 6667);
17
18 while (true)
19 {
20 if ((pClient = socket.Accept()) != NULL)
21 {
22 int clientPort = socket.GetClientPort();
23 printf("connected from %s:%d\n", socket.GetClientAddr(), clientPort);
24 //----------------------------------------------------------------------
25 // Receive request from the client.
26 //----------------------------------------------------------------------
27 while (1)
28 {
29 //printf("try receive\n");
30 bool receivedData = false;
31 int recBytes = 0;
32 recBytes = pClient->Receive(MAX_PACKET);
33 if (recBytes)
34 {
35 char *msg = (char *)pClient->GetData();
36 msg[recBytes] = 0;
37 printf("received message [%s]\n", msg);
38 //------------------------------------------------------------------
39 // Send response to client and close connection to the client.
40 //------------------------------------------------------------------
41 pClient->Send(pClient->GetData(), pClient->GetBytesReceived());
42 receivedData = true;
43 if (strncmp(msg, "stop", 4) == 0)
44 {
45 printf("Stop request received\n");
46 break;
47 }
48 }
49 if (!receivedData)
50 {
51 printf("Didn't receive data.\n");
52 break;
53 }
54 }
55 printf("Disconnecting client.\n");
56 pClient->Close();
57 delete pClient;
58 }
59 }
60
61 //-----------------------------------------------------------------------------
62 // Receive request from the client.
63 //-----------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 10

ListenMethod · 0.80
GetClientPortMethod · 0.80
GetClientAddrMethod · 0.80
ReceiveMethod · 0.80
GetDataMethod · 0.80
GetBytesReceivedMethod · 0.80
InitializeMethod · 0.45
AcceptMethod · 0.45
SendMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected