' Demonstrates a client that can receive and play received data Imports System.Windows.Forms Imports System.Threading Module Module1 ' Returns true if the control key is down Public Function CtrlKeyDown() As Boolean Dim bReturn As Boolean = False Dim ModKeyDown As Keys = Control.ModifierKeys If ModKeyDown = Keys.Control Then bReturn = True End If Return (bReturn) End Function Sub Main() Dim iResult As Integer Dim InputData As Long = mn.CreatePacket() Dim RecvPacket As Long = mn.CreatePacket() ' Connect to server Dim IP As String Dim Port As UShort = 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) Select (iResult) Case (1) Console.WriteLine("Connected to server") Console.WriteLine("Local TCP Port: " + mn.GetLocalIPTCP(0)) Console.WriteLine("Local TCP Port: " + mn.GetLocalPortTCP(0).ToString()) Console.WriteLine("Local UDP IP: " + mn.GetLocalIPUDP(0)) Console.WriteLine("Local UDP Port: " + mn.GetLocalPortUDP(0).ToString()) Case (0) Console.WriteLine("Failed to connect: timed out") Console.WriteLine("Press any key to exit...") Console.ReadKey() Return Case (-1) Console.WriteLine("Failed to connect: an unknown error occurred") Console.WriteLine("Press any key to exit...") Console.ReadKey() Return Case (-2) Console.WriteLine("Failed to connect: the server is full") Console.WriteLine("Press any key to exit...") Console.ReadKey() Return End Select ' Setup sound mn.StartSound(1, mn.GetMaxClients(0) + 1) mn.StartInput(0, UInteger.MaxValue) For n = 1 To mn.GetMaxClients(0) mn.StartOutput(n, UInteger.MaxValue) Next n ' Main loop While mn.ClientConnected(0, 0) = 1 Thread.Sleep(1) ' Toggle sound input If CtrlKeyDown() = True Then If mn.GetInputUnpaused(0) = 0 Then mn.UnpauseInput(0) Console.WriteLine("Input unpaused") End If Else If mn.GetInputPaused(0) = 0 Then mn.PauseInput(0) Console.WriteLine("Input paused") End If End If ' Input data iResult = mn.GetInputData(0, InputData) If iResult > 0 Then ' Send data to server mn.SendUDP(0, InputData, 0, False, True) End If ' Packets from server iResult = mn.RecvUDP(0, RecvPacket, 0, 0) If iResult > 0 Then ' Play data Dim iClient As Integer = mn.GetInt(RecvPacket) mn.Erase(RecvPacket, 0, 4) mn.PlayData(iClient, RecvPacket) End If End While Console.WriteLine("Disconnected from server") mn.FinishSound() mn.Finish(-1) Console.WriteLine("Press any key to exit...") Console.ReadKey() Return End Sub End Module