static void Main(string[] args) { var serverExecutable = @"E:\Dropbox\!Coding\All_in_one\Proiznoshator\Server\bin\Debug\Server.exe"; //Process.Start(serverExecutable); WaitForConnection(); Console.Write("Введите имя: "); name = Console.ReadLine(); Console.Title = name; playMessagesFromQueThread = new Thread(new ThreadStart(PlayMessagesFromQue)); playMessagesFromQueThread.IsBackground = true; playMessagesFromQueThread.Start(); while (true) { Console.Write("Введите сообщение: "); var text = Console.ReadLine(); var message = String.Format("{0} говорит: {1}", name, text); var testVoice = new VoicePackage("test voice", 0, 100, message).ToByteArray(); client.Send(testVoice); Console.WriteLine(); } }
private static void ReceiveCallback(IAsyncResult AR) { Socket current = (Socket)AR.AsyncState; int received; try { Debug.WriteLine("Client: receive callback"); received = current.EndReceive(AR); } catch (SocketException) { Debug.WriteLine("Client: receive callback failed"); current.Close(); // Dont shutdown because the socket may be disposed and its disconnected anyway //_clientSockets.Remove(current); return; } byte[] recBuf = new byte[received]; Array.Copy(_buffer, recBuf, received); //string text = Encoding.UTF8.GetString(recBuf); var receivedVoice = new VoicePackage(recBuf); // TESTING //MessageBox.Show("client : " + receivedVoice.Text); Debug.WriteLine("Client: received text: " + receivedVoice.Text); Globals.messagesQue.Add(receivedVoice); //Console.WriteLine("Received Text: " + text); //if (text.ToLower() == "get time") // Client requested time //{ // Console.WriteLine("Text is a get time request"); // byte[] data = Encoding.ASCII.GetBytes(DateTime.Now.ToLongTimeString()); // current.Send(data); // Console.WriteLine("Time sent to client"); //} //else if (text.ToLower() == "exit") // Client wants to exit gracefully //{ // // Always Shutdown before closing // current.Shutdown(SocketShutdown.Both); // current.Close(); // _clientSockets.Remove(current); // Console.WriteLine("Client disconnected"); // return; //} //else //{ // Console.WriteLine("Text is an invalid request"); // byte[] data = Encoding.ASCII.GetBytes("Invalid request"); // current.Send(data); // Console.WriteLine("Warning Sent"); //} try { Debug.WriteLine("Client: try begin receive"); current.BeginReceive(_buffer, 0, _BUFFER_SIZE, SocketFlags.None, ReceiveCallback, current); } catch { Debug.WriteLine("Client: try begin receive failed"); } }