` Demonstrates a client that can receive and play received data iResult as integer InputData = mn Create Packet() RecvPacket = mn Create Packet() ` Connect to server IP as string Port as integer PushToTalkKey as integer input "Enter an IP to connect to: ",IP input "Enter a port to connect to: ", Port$ Port = val(Port$) print "Press a key to be your 'push to talk' button" print "Waiting for key press..." Sleep 500 while PushToTalkKey = 0 for n = 0 to 200 if KeyDown(n) = 1 PushToTalkKey = n print "Key press detected" exit endif next n endwhile print "Connecting..." mn Start 1,0 mn Set Buffer Sizes 0,15000,1024,2 iResult = mn Connect(0,IP,Port,IP,Port,5,1) print iResult select iResult case 1: print "Connected to server" print "Local TCP Port: " + mn Get Local IP TCP(0) print "Local TCP Port: " + str$(mn Get Local Port TCP(0)) print "Local UDP IP: " + mn Get Local IP UDP(0) print "Local UDP Port: " + str$(mn Get Local Port UDP(0)) endcase case 0: print "Failed to connect: timed out" print "Press any key to exit..." wait key end endcase case -1: print "Failed to connect: an unknown error occurred" print "Press any key to exit..." wait key end endcase case -2: print "Failed to connect: the server is full" print "Press any key to exit..." wait key end endcase endselect ` Setup sound mn Start Sound 1,mn Get Max Clients(0)+1 mn Start Input 0,-1 for n = 1 to mn Get Max Clients(0) mn Start Output n,-1 next n ` Main loop while mn Client Connected(0,0) = 1 ` Toggle sound input if KeyDown(PushToTalkKey) = 1 if mn Get Input Unpaused(0) = 0 mn Unpause Input 0 print "Input unpaused" endif else if mn Get Input Paused(0) = 0 mn Pause Input 0 print "Input paused" endif endif ` Input data iResult = mn Get Input Data(0,InputData) if iResult > 0 ` Send data to server mn Send UDP 0,InputData,0,0,1 endif ` Packets from server iResult = mn Recv UDP(0,RecvPacket,0,0) if iResult > 0 ` Play data iClient = mn Get Int(RecvPacket) mn Erase RecvPacket,0,4 mn Play Data iClient,RecvPacket endif endwhile print "Disconnected from server" mn Finish Sound mn Finish -1 print "Press any key to exit..." wait key end ` Returns 1 if specified key is down function KeyDown(vKey as integer) bool as boolean if (get key state(vKey) < 0) then bool = 1 else bool = 0 endfunction bool