C# Socket 关闭服务,如何关闭当前已经连接的socket RT。采用C#求解决方案目前server的socket主动close之后,listening没了。但是还有2个ES状态。说明服务器只是关闭了监听,但是客户端的连接没有主动close。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private bool Connect_Utils() { bool flag = true; try { if (serverProxy == null || serverProxy.State != CommunicationState.Opened) { NetTcpBinding binding = new NetTcpBinding(SecurityMode.None); binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; binding.TransferMode = TransferMode.Buffered; binding.TransactionFlow = false; binding.TransactionProtocol = TransactionProtocol.OleTransactions; binding.MaxBufferPoolSize = 2147483647; binding.MaxBufferSize = 2147483647; binding.MaxConnections = 32; binding.MaxReceivedMessageSize = 2147483647; binding.ReaderQuotas.MaxArrayLength = 2147483647; string addr = "net.tcp://192.168.1.2:9000/server"; serverProxy = new ServerProxy(new InstanceContext(this), binding, new EndpointAddress(addr)); serverProxy.Open();//打开服务 flag = true; } } catch (Exception Ex) { MessageBox.Show("连接服务器时发生错误" + Ex.Message, "连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error); flag = false; } return flag; }以上为连接服务以下为关闭服务if(serverProxy == null || serverProxy.State != CommunicationState.Opened){ serverProxy.Close();} http://blog.csdn.net/fengyarongaa/article/details/6631953 可能我描述的有问题或不太清楚。我的意思是我是server端。Listen之后,一直在等待客户端连接(同步短连接)现在服务器在运行,我想手工停止server服务器,现在的程序是listen是停止了,客户端肯定是连接不上来了。但是之前已经连接的客户端,只要客户端没主动关闭,还是可以直接发送接收数据,因为连接的状态为ESTABLISHED状态。我的问题是服务器主动关闭后,要求lister停止,并关闭所有已经连接的客户端(服务器主动关闭客户端的连接) datagrideview 如何使光标停在一固定单元格 Linq to sql 如何设置要连接的数据库? 求GridView自动更新数据的例子 程序设计思路 网络传输图片问题,急啊。那位大哥帮忙解答啊,小弟这里谢谢了,赶进度啊!!!!!!!! 请教web service问题??? ie中如何设置A3纸的页边距 一个简单 问题,如何在 string 中夹个参数值? 如何用C#做出一个可以制作flash的软件(不是播放器) 求ERP的电子书、资料 未将对象引用设置到对象的实例,怎么修改 vs
{
bool flag = true;
try
{
if (serverProxy == null || serverProxy.State != CommunicationState.Opened)
{
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
binding.TransferMode = TransferMode.Buffered;
binding.TransactionFlow = false;
binding.TransactionProtocol = TransactionProtocol.OleTransactions; binding.MaxBufferPoolSize = 2147483647;
binding.MaxBufferSize = 2147483647;
binding.MaxConnections = 32;
binding.MaxReceivedMessageSize = 2147483647;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
string addr = "net.tcp://192.168.1.2:9000/server";
serverProxy = new ServerProxy(new InstanceContext(this), binding, new EndpointAddress(addr));
serverProxy.Open();//打开服务
flag = true;
}
}
catch (Exception Ex)
{
MessageBox.Show("连接服务器时发生错误" + Ex.Message, "连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
flag = false;
}
return flag;
}
以上为连接服务
以下为关闭服务if(serverProxy == null || serverProxy.State != CommunicationState.Opened)
{
serverProxy.Close();
}
Listen之后,一直在等待客户端连接(同步短连接)现在服务器在运行,我想手工停止server服务器,现在的程序是listen是停止了,客户端肯定是连接不上来了。
但是之前已经连接的客户端,只要客户端没主动关闭,还是可以直接发送接收数据,因为连接的状态为ESTABLISHED状态。我的问题是服务器主动关闭后,要求lister停止,并关闭所有已经连接的客户端(服务器主动关闭客户端的连接)