// Demonstrates a client that can receive and play received data using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace Client { class Program { // Returns true if the control key is down static bool CtrlKeyDown() { bool bReturn = false; Keys ModKeyDown = Control.ModifierKeys; if (ModKeyDown == Keys.Control) { bReturn = true; } return(bReturn); } static void Main(string[] args) { int iResult; Int64 InputData = mn.CreatePacket(); Int64 RecvPacket = mn.CreatePacket(); // Connect to server string IP; ushort Port = 0; Console.WriteLine("Enter an IP to connect to: "); IP = Console.ReadLine(); Console.WriteLine("Enter a port to connect to: "); Port = Convert.ToUInt16(Console.ReadLine()); Console.WriteLine("Your push to talk key is the CTRL key"); Console.WriteLine(); Console.WriteLine("Connecting..."); mn.Start(1,0); mn.SetBufferSizes(0,15000,1024,2); iResult = mn.Connect(0,IP,Port,IP,Port,5,true); switch(iResult) { case(1): Console.WriteLine("Connected to server"); Console.WriteLine("Local TCP Port: " + mn.GetLocalIPTCP(0)); Console.WriteLine("Local TCP Port: " + mn.GetLocalPortTCP(0)); Console.WriteLine("Local UDP IP: " + mn.GetLocalIPUDP(0)); Console.WriteLine("Local UDP Port: " + mn.GetLocalPortUDP(0)); break; case(0): Console.WriteLine("Failed to connect: timed out"); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); return; break; case(-1): Console.WriteLine("Failed to connect: an unknown error occurred"); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); return; break; case(-2): Console.WriteLine("Failed to connect: the server is full"); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); return; break; } // Setup sound mn.StartSound(1,mn.GetMaxClients(0)+1); mn.StartInput(0,uint.MaxValue); for(int n = 1;n<=mn.GetMaxClients(0);n++) { mn.StartOutput(n,uint.MaxValue); } // Main loop while(mn.ClientConnected(0,0) == 1) { Thread.Sleep(1); // Toggle sound input if (CtrlKeyDown() == true) { if(mn.GetInputUnpaused(0) == 0) { mn.UnpauseInput(0); Console.WriteLine("Input unpaused"); } } else { if(mn.GetInputPaused(0) == 0) { mn.PauseInput(0); Console.WriteLine("Input paused"); } } // Input data iResult = mn.GetInputData(0,InputData); if(iResult > 0) { // Send data to server mn.SendUDP(0,InputData,0,false,true); } // Packets from server iResult = mn.RecvUDP(0,RecvPacket,0,0); if(iResult > 0) { // Play data int iClient = mn.GetInt(RecvPacket); mn.Erase(RecvPacket,0,sizeof(int)); mn.PlayData(iClient,RecvPacket); } } Console.WriteLine("Disconnected from server"); mn.FinishSound(); mn.Finish(-1); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); return; } } }