2种不同的代码(tcp/ip client),哪个效率相对来说好一些. 有什么区别么?TCPCLINT继承自socket使用起来应该是一样的啊. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不是继承关系而是对sock的封装吧 不是继承关系而是对sock的封装吧嗯,大概吧,反正不引用socket,tcpclint也用不了.最后还是调用的socket 按照你的写法,两种都一样。或者说第二种没有用上TcpClient封装的功能(NetwokStream)。Socket.Shutdown没有问题。但如果客户很经常发消息,比如一分钟几个,那么就好复用Socket,而不是马上关闭。 一个是米饭,一个是饭团,形状不同,呵呵c.Client 就是 Socket, 虽然是二道贩子,但不影响速度. TcpClient/TcpListener是比Socket高级的。虽然它使用了Socket,TcpClient.Client 就是socket 类型的对象,但是进行了高级的重写改造。特别地,Socket是按照古老的方式而实现的,是为了与linux通用代码兼容;而TcpListner/TcpClient则是专门针对使用windows的IOCP而重写的! 以前我们有一些c++程序员,他们开会时总是“煞有介事”地说“在windows上的socket通讯应该选择IOCP才好啊”。这对于使用TcpListener/Tcpclient的人会暗自好笑,但是不好戳破他们。如果戳破则会说“我们c#程序员不动脑子也已经使用了IOCP了啊”。如果有两种结构,一种是低级的而另一种是高级扩展。那么只要高级的在性能上你不能证明其很差,通常就应该赶紧掌握高级的东西,少用低级的东西(虽然低级的东西是上学时要学的基础知识)。 嗯我举一个反例。我们不但有真正的测试,而且在一两个大项目上也有几个月的教训,证明.net的WCF性能很差,比基本的HTTP差很多(甚至在VPN上运行时经常造成一些小事故,而改为HTTP轻量级方式则整年都运行得很好)。这时候,你就不能选择高级的了,应该在低级的东西上自己动手进行扩充。一个高级的东西如果它不好用,你就自己动手改造它、甚至自己推出一个,以达到甚至超越它。不能墨守成规地退一步以为“越是低级的东西越好”。 TCPCLIENTpublic void Connect(IPAddress[] ipAddresses, int port){ if (Logging.On) { Logging.Enter(Logging.Sockets, this, "Connect", ipAddresses); } this.Client.Connect(ipAddresses, port); this.m_Active = true; if (Logging.On) { Logging.Exit(Logging.Sockets, this, "Connect", (string) null); }} SOCKETpublic void Connect(IPAddress address, int port){ if (s_LoggingEnabled) { Logging.Enter(Logging.Sockets, this, "Connect", address); } if (this.CleanedUp) { throw new ObjectDisposedException(base.GetType().FullName); } if (address == null) { throw new ArgumentNullException("address"); } if (!ValidationHelper.ValidateTcpPort(port)) { throw new ArgumentOutOfRangeException("port"); } if (!this.CanTryAddressFamily(address.AddressFamily)) { throw new NotSupportedException(SR.GetString("net_invalidversion")); } IPEndPoint remoteEP = new IPEndPoint(address, port); this.Connect(remoteEP); if (s_LoggingEnabled) { Logging.Exit(Logging.Sockets, this, "Connect", (string) null); }}这种东西根本就没什么讨论的必要,底层都是一样的东西。纠结在这些小事上白白浪费的时间不如学些新东西 c#调用delphi dll 参数传递问题 有开发智能卡经验的进来看看!! 服务器控件 checkbox 怎么限制选择个数! 超级简单的Request.QueryString问题! vb.net中的vbCrLf在c#里面用代替 vc到c# 请来个高手帮我把这两个方法转成函数,谢谢拉 各位大侠,请问在两个子窗体这间怎么进行切换?? 关于Console.writeln格式串的问题。 C#英文网站征集,请给出网站连接及其简单的介绍.灌水勿进,不是算分. 多线程应用 WPF DataGrid 赋值问题
嗯,大概吧,反正不引用socket,tcpclint也用不了.
最后还是调用的socket
Socket.Shutdown没有问题。但如果客户很经常发消息,比如一分钟几个,那么就好复用Socket,而不是马上关闭。
c.Client 就是 Socket, 虽然是二道贩子,但不影响速度.
public void Connect(IPAddress[] ipAddresses, int port)
{
if (Logging.On)
{
Logging.Enter(Logging.Sockets, this, "Connect", ipAddresses);
}
this.Client.Connect(ipAddresses, port);
this.m_Active = true;
if (Logging.On)
{
Logging.Exit(Logging.Sockets, this, "Connect", (string) null);
}
} SOCKET
public void Connect(IPAddress address, int port)
{
if (s_LoggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "Connect", address);
}
if (this.CleanedUp)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (address == null)
{
throw new ArgumentNullException("address");
}
if (!ValidationHelper.ValidateTcpPort(port))
{
throw new ArgumentOutOfRangeException("port");
}
if (!this.CanTryAddressFamily(address.AddressFamily))
{
throw new NotSupportedException(SR.GetString("net_invalidversion"));
}
IPEndPoint remoteEP = new IPEndPoint(address, port);
this.Connect(remoteEP);
if (s_LoggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "Connect", (string) null);
}
}这种东西根本就没什么讨论的必要,底层都是一样的东西。
纠结在这些小事上白白浪费的时间不如学些新东西