// Demonstrates a server that receives sound data from clients // and relays it to other clients #include #include using namespace std; void main() { int iResult; long long int RecvPacket = mnCreatePacket(); // Start server cout << "Starting server...\n"; mnStart(1,0); mnSetLocal(0,"",2525,"",2525); mnSetBufferSizes(0,15000,1024,STATE_SERVER); mnStartServer(0,50,0,UM_CATCH_ALL_NO); cout << "Server started\n"; cout << "Local TCP IP: " << mnGetLocalIPTCP(0) << '\n'; cout << "Local TCP port: " << mnGetLocalPortTCP(0) << '\n'; cout << "Local UDP IP: " << mnGetLocalIPUDP(0) << '\n'; cout << "Local UDP port: " << mnGetLocalPortUDP(0) << '\n'; cout << '\n'; // Main loop bool bRunning = true; while(bRunning == true) { Sleep(1); // Accept new connections iResult = mnClientJoined(0); if(iResult > 0) { cout << "New client joined: " << iResult << '\n'; cout << "Client TCP IP: " << mnGetClientIPTCP(0,iResult) << '\n'; cout << "Client TCP port: " << mnGetClientPortTCP(0,iResult) << '\n'; cout << "Client UDP IP: " << mnGetClientIPUDP(0,iResult) << '\n'; cout << "Client UDP port: " << mnGetClientPortUDP(0,iResult) << '\n'; } // Leaving clients iResult = mnClientLeft(0); if(iResult > 0) { cout << "Client left: " << iResult << '\n'; } // New TCP packets for(int cl = 1;cl<=mnGetMaxClients(0);cl++) { iResult = mnRecvUDP(0,RecvPacket,cl,0); if(iResult > 0) { // Add client ID to start of packet mnSetCursor(RecvPacket,0); mnInsert(RecvPacket,sizeof(int)); mnAddInt(RecvPacket,cl); // Send packet to clients mnSendUDPAll(0,RecvPacket,false,true,cl); } } } }