我有一个奇怪的问题:我写了一个基于.net2的服务器和客户端,它们正在通过.net 2 SslStream聊天。有1个连接用于在Cl和S之间发送命令,以及一个用于在cl和s之间发送文件的连接。
本地所有在我的Windows机器上工作正常。但是,如果我在我的Linux服务器上运行服务器(使用单声道),共享文件在某些情况下不起作用。我有不同的文件类别,第3个中的2个工作,第3个中的服务器挂在SSLStream.AuthenticateAsServer(....);
上,并且客户端抛出异常,并显示消息“对SSPI调用失败,请参阅内部异常”。 Innerexception是一个System.ComponentModel.Win32Exception异常与消息“收到的消息是意外或格式不正确。”SSLStream:“调用SSPI失败”异常
我认为我在Linux上运行它的方式可能是错误的。其实我使用VS2012进行本地开发,当我想把它放在服务器上时,我使用mono server.exe
上传VS和Im编译的exe来启动它。但我也尝试在Windows上使用monodevelop来编译它(从monodevelop编译的东西也可以在本地工作)并在Linux服务器上使用它,但是这会以相同的结果结束。
任何帮助将不胜感激。
我的继承人缩短代码:
客户:
//gets auth guid before, then it does
Thread Thre = new Thread(sendfile);
Thre.Start(authguid);
private void sendfile(string guid){
TcpClient cl = new TcpClient();
cl.Connect(hostname, 8789);
SslStream Stream = new SslStream(cl.GetStream(), true, new RemoteCertificateValidationCallback(ServerConnector.ValidateServerCertificate));
Stream.AuthenticateAsClient(hostname);//throws the exception
//sends auth guid and file
}
服务器:
public class FServer
{
protected static bool halt = false;
protected List<FConnection> connections;
private TcpListener tcpServer;
private IPEndPoint ipEnde = new IPEndPoint(IPAddress.Any, 8789);
private delegate void dlgAccept();
private dlgAccept accepting;
private IAsyncResult resAccept;
public FServer()
{
tcpServer = new TcpListener(ipEnde);
connections = new List<FConnection>();
tcpServer.Start();
accepting = new dlgAccept(accept);
resAccept = accepting.BeginInvoke(null, null);
}
public void accept()
{
do
{
if (tcpServer.Pending())
connections.Add(new FConnection(tcpServer.AcceptTcpClient(), this));
else
Thread.Sleep(750);
} while (!halt && tcpServer != null);
}
public class FConnection
{
public SslStream stream;
//.....some other properties
public static bool ValidateClientCertificate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
public FConnection(TcpClient cl, FServer inst)
{
instance = inst;
client = cl;
stream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateClientCertificate), null);
stream.AuthenticateAsServer(instance.mainserver.serverCert, false, SslProtocols.Tls, false);//hangs sometimes on this
if (stream.IsAuthenticated && stream.IsEncrypted)
{
}
else
{
this.Dispose();
}
//auth and receiving file
}
}
}
为什么同样的方法不为我工作?即使上面提到的变化发生,我也会得到同样的错误。 –
有人帮我吗? –
嗨。我也有同样的问题。即使你改变了这个问题也没有修复。不知道有更多的信息? – virtouso