Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
连接和登录授权到;接口转换器Ethernet-RS485“;像TCP服务器c#UWP一样工作_C#_Sockets_Tcp_Uwp - Fatal编程技术网

连接和登录授权到;接口转换器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();
}