C ++客户端仅适用于localhost C#Server

时间:2017-03-31 16:09:20

标签: c# c++ sockets

我正在使用C ++应用程序,即Windows服务和C#服务器。 使用localhost测试一切都很好,但使用virtualbox系统或相同的网络计算机它不起作用。 我禁用了Windows防火墙和防病毒软件。 这是我的C#Server最重要的代码:

\n-----END CERTIFICATE-----

这是我的C ++客户端最重要的代码(根据c ++套接字客户端的msdn示例):

#!/usr/bin/env python

import jwt
from cryptography.x509 import load_pem_x509_certificate
from cryptography.hazmat.backends import default_backend

PEMSTART = "-----BEGIN CERTIFICATE-----\n"
PEMEND = "\n-----END CERTIFICATE-----\n"

mspubkey = "The value from the x5c property"
IDTOKEN = "the id_token to be validated"
tenant_id = "your tenant id"

cert_str = PEMSTART + mspubkey + PEMEND
cert_obj = load_pem_x509_certificate(cert_str, default_backend())
public_key = cert_obj.public_key()

decoded = jwt.decode(IDTOKEN, public_key, algorithms=['RS256'], audience=tenant_id)
if decoded:
    print "Decoded!"
else:
    print "Could not decode token."

使用localhost可以工作,我的客户端和服务器在同一个ip上但具有不同的端口。 有了不同的ips我得到的情况是服务器没有听到'客户。 我的日志看起来像这样:

   IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
    IPAddress ipAddress = IPAddress.Parse("192.168.1.2");
    IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 8517);
    tcpListener = new TcpListener(localEndPoint);
    tcpListener.Start();
    tcpListenerThread = new Thread(listenerSocket);
    tcpListenerThread.Start();
}

static void listenerSocket()
{
     while (true)
     {
          try
          {
              Socket client = tcpListener.AcceptSocket();
              clientSockets.Add(client);
          }
          catch (Exception exc)
          {
               return;
          }
      }
}

我非常感谢任何帮助我坚持这一近一周。 我可以添加ping到服务器IP在客户端PC上工作

0 个答案:

没有答案