连接和登录授权到;接口转换器Ethernet-RS485“;像TCP服务器c#UWP一样工作
我需要连接到本地网络上的设备。 设备要求输入用户名和密码。如何输入它们? 连接后设备是否应发送密码请求 设备: 我尝试这样登录:连接和登录授权到;接口转换器Ethernet-RS485“;像TCP服务器c#UWP一样工作,c#,sockets,tcp,uwp,C#,Sockets,Tcp,Uwp,我需要连接到本地网络上的设备。 设备要求输入用户名和密码。如何输入它们? 连接后设备是否应发送密码请求 设备: 我尝试这样登录: public void Connect() { var tcpClient = new TcpClient("192.168.88.1",80); var ns = tcpClient.GetStream(); Byte[] output = new Byte[1024]; String response = St
public void Connect()
{
var tcpClient = new TcpClient("192.168.88.1",80);
var ns = tcpClient.GetStream();
Byte[] output = new Byte[1024];
String response = String.Empty;
Byte[] cmd = System.Text.Encoding.ASCII.GetBytes("\n");
ns.Write(cmd, 0, cmd.Length);
Thread.Sleep(100);
Int32 bytes = ns.Read(output, 0, output.Length);
response = System.Text.Encoding.ASCII.GetString(output, 0, bytes);
Regex objToMatch = new Regex("Login");
if (objToMatch.IsMatch(response))
{
cmd = System.Text.Encoding.ASCII.GetBytes("admin" + "\r");
ns.Write(cmd, 0, cmd.Length);
}
Thread.Sleep(100);
bytes = ns.Read(output, 0, output.Length);
response = System.Text.Encoding.ASCII.GetString(output, 0, bytes);
objToMatch = new Regex("Password");
if (objToMatch.IsMatch(response)) //Both Regex match
{
cmd = System.Text.Encoding.ASCII.GetBytes("" + "\r");
ns.Write(cmd, 0, cmd.Length);
}
Thread.Sleep(100);
bytes = ns.Read(output, 0, output.Length);
response = System.Text.Encoding.ASCII.GetString(output, 0, bytes);
cmd = System.Text.Encoding.ASCII.GetBytes("\r");
ns.Write(cmd, 0, cmd.Length); //Cannot send because connection is closed
tcpClient.Close();
}