简体   繁体   English

是一个读取端口,一个端口用于为套接字应用程序写一个好主意吗?

[英]Is one port for read, one port for write a good idea for socket applications?

I am wondering if it is a good idea to have 2 separate ports one for read, one for write ? 我想知道两个独立的端口是否一个用于读取,一个用于写入是一个好主意? Can I expect better performance ? 我可以期待更好的性能吗?

NOTE: Server is Centos, Client is flash, message format in communication is JSON. 注意:服务器是Centos,客户端是flash,通信中的消息格式是JSON。

There's no significant performance advantage, and it can require much more code to handle two sockets than one, particularly on the server side. 性能没有明显的优势,处理两个套接字所需的代码要比一个套接字多得多,尤其是在服务器端。

You'd also still have to open both sockets from the client side, as most systems wouldn't permit the server to open a connection back to the client. 您还仍然必须从客户端打开两个套接字,因为大多数系统不允许服务器打开与客户端的连接。

AFAIK, TCP is optimised assuming you will send a request and get a response on the same socket, however the difference is likely to be trivial. AFAIK,TCP已优化,假设您将发送请求并在同一套接字上获得响应,但差异可能很小。

Often the simplest solution is also the fastest. 通常最简单的解决方案也是最快的。

What is the problem you are trying to solve? 你想解决的问题是什么?

Best to have it in TCP with a single port, also depending if you are using NIO or not, 最好通过单个端口在TCP中使用它,这还取决于您是否使用NIO,

Just in case you want to have 2 ports & Unless its not a TCP (eg UDP) 以防你想拥有2个端口&除非它不是TCP(例如UDP)

If you are in Cent OS 32 bit, ensure that your kernel to use up more ports that it should. 如果您使用的是Cent OS 32位,请确保您的内核使用更多应该使用的端口。

This is to prevent port starvation & would quickly cripple your server. 这是为了防止端口匮乏,并会迅速削弱您的服务器。

Do the math, if you need to support 100 users, 100 x 2 = 200 open ports. 算一下,如果您需要支持100个用户,则100 x 2 = 200个开放端口。

but in most cases, its only (65534 - 1024) ports available, so, if you could afford it, then its cool. 但在大多数情况下,它只有(65534 - 1024)个端口可用,因此,如果你能负担得起,那就很酷了。

Also remember that most ISP's would block certain ports, so keep the right ports open for read / write. 还请记住,大多数ISP都会阻塞某些端口,因此请保持正确的端口开放以进行读取/写入。

regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM