// Connect to the asterisk server. Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("192.168.10.250"), 5038); clientSocket.Connect(serverEndPoint); // Login to the server; manager.conf needs to be setup with matching credentials. clientSocket.Send(Encoding.ASCII.GetBytes("Action: Login\r\nUsername: administrator\r\nSecret: neven1206\r\nActionID: 1\r\n\r\n")); int bytesRead = 0; do { byte[] buffer = new byte[1024]; bytesRead = clientSocket.Receive(buffer); Console.WriteLine(bytesRead.ToString()); //Console.WriteLine(bytesRead + " bytes from asterisk server."); string response = Encoding.ASCII.GetString(buffer, 0, bytesRead); Console.WriteLine(response); } while (bytesRead != 0); Console.WriteLine("Connection to server lost."); Console.ReadLine(); }
Console.WriteLine("Connection to server lost."); part of code. I don't know what i'm doing wrong. Please help