CSHARP 31
Yeastar tcp client c# code example Guest on 5th February 2025 06:50:04 AM
  1. using System;
  2. using System.IO;
  3. using System.Net.Sockets;
  4. using System.Text;
  5.  
  6. class YeastarGT400Client
  7. {
  8.     private const string Host = "192.168.5.150"; // Replace with your GT400's IP address
  9.     private const int Port = 5038; // Default port for Yeastar API
  10.     private const string Username = "administrator"; // Replace with your API username
  11.     private const string Password = "P@ssw0rd"; // Replace with your API password
  12.  
  13.     static void Main()
  14.     {
  15.         try
  16.         {
  17.             using (TcpClient client = new TcpClient(Host, Port))
  18.             using (NetworkStream stream = client.GetStream())
  19.             using (StreamReader reader = new StreamReader(stream, Encoding.ASCII))
  20.             using (StreamWriter writer = new StreamWriter(stream, Encoding.ASCII) { AutoFlush = true })
  21.             {
  22.                 // Read the initial response from the server
  23.                 string response = reader.ReadLine();
  24.                 Console.WriteLine("Server: " + response);
  25.  
  26.                 // Send login command
  27.                 writer.WriteLine($"Action: Login\r\nUsername: {Username}\r\nSecret: {Password}\r\n\r\n");
  28.  
  29.                 // Read login response
  30.                 response = reader.ReadLine();
  31.                 Console.WriteLine("Server: " + response);
  32.  
  33.                 // Send SMS command
  34.                 string smsCommand = "Action: smscommand\r\ncommand: gsm send sms 1 1234567890 \"Hello, this is a test message.\"\r\n\r\n";
  35.                 writer.WriteLine(smsCommand);
  36.  
  37.                 // Read SMS send response
  38.                 response = reader.ReadLine();
  39.                 Console.WriteLine("Server: " + response);
  40.  
  41.                 // Logoff
  42.                 writer.WriteLine("Action: Logoff\r\n\r\n");
  43.             }
  44.         }
  45.         catch (Exception ex)
  46.         {
  47.             Console.WriteLine("Error: " + ex.Message);
  48.         }
  49.     }
  50. }

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.