const string ipAddressString = "192.168.1.217";// replace with correct IP address IPAddress ipAddress = IPAddress.Parse(ipAddressString); const int portNum = 8021;// replace with correct port IPEndPoint remoteEndPoint = new IPEndPoint(ipAddress, portNum);
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); client.SendTimeout =Convert.ToInt16( txtTimeOut.Value); client.Connect(remoteEndPoint); string sendString = "auth ClueCon\n\n"; byte[] sendBuffer = Encoding.UTF8.GetBytes(sendString.ToString()); client.Send(sendBuffer); byte[] receiveBuffer = new byte[10000]; sendString = "api commands to make call " + "\n\n"; Page.Title = Select1.Items[Select1.SelectedIndex].Text; sendBuffer = Encoding.UTF8.GetBytes(sendString.ToString()); client.Send(sendBuffer);
bufferString = ""; int i =0; client.ReceiveTimeout =Convert.ToInt16( txtTimeOut.Value ); Label1.Text = ""; try { while (bufferString.Length < 1000) { client.Receive(receiveBuffer, 0, receiveBuffer.Length, SocketFlags.None); bufferString = System.Text.Encoding.GetEncoding(949).GetString(receiveBuffer); bufferString = bufferString.Replace("\0", ""); }
} catch (Exception ex) { Label1.Text = ex.Message; }
client.Shutdown(SocketShutdown.Both); client.Close();
|