最好的想法是使用自定义服务器应用程序吗? [英] Is this best idea to use custom server application?

查看:64
本文介绍了最好的想法是使用自定义服务器应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过互联网在PC和Android的客户端应用程序之间传输数据。所以我需要一台服务器。



从客户端,我需要进行民意调查服务器是否有来自其他客户端的数据。

如果有,我需要连接到服务器来检索数据。



For我计划使用套接字,因为我可以在一个连接中传输大量数据。



首先我计划使用PHP套接字,但PHP套接字只允许一个一次请求。

那么我计划使用带有SSL套接字的Java自定义服务器应用程序。



要设置服务器,我'我将获得VPS并在该vps中执行Java应用程序。



这是最好的主意吗?

解决方案

< blockquote>请看我对这个问题的评论。



不仅每个线程的客户端太多,同时还不够。服务器端需要至少两个通信线程用于两个不同的目的:一个用于侦听新连接,另一个用于发送/接收数据。请查看我过去的答案:

插座编程中的业余问题 [< a href =http://www.codeproject.com/Answers/536542/anplusamateurplusquestionplusinplussocketplusprogr#answer2target =_ blanktitle =New Window> ^ ],

< a href =http://www.codeproject.com/Answers/165297/Multple-clients-from-same-port-Number#answer1>来自同一端口号码的多个客户端 [ ^ ],

如何知道AA Tcp连接是否结束 [ ^ ]。



另外,你提到轮询服务器。为什么轮询服务器为任何请求?请求的含义是不同的;这是可以在任何时候完成的事情。但是如果你真的需要轮询(通常是在某些活动完成的时刻),这是另一个坏主意。您需要了解客户端 - 服务器模型是一个非常糟糕的限制模型。请参阅我以前的回答:网站帐户的应用程序'信息中心 [ ^ ]。



现在,好的一面是:使用套接字,您不受客户端服务器的限制。可以轻松实现上面引用的帖子中提到的服务器推送。例如,您可以实现应用层协议,实现已发布订阅者或其与客户端 - 服务器的组合,或类似的任何内容。请注意,即使您不将其称为协议,也始终在传输层协议之上实现某些应用程序级协议。所以,最好不要假装你没有明确地做。当然,这个应用层将定制为自定义服务(我更喜欢称之为服务,而不是服务器,以避免暗示命名引用纯客户端 - 服务器。)请参阅:

http://en.wikipedia.org/wiki/Application_layer [ ^ ],

http://en.wikipedia.org/wiki/Transport_layer [ ^ ],

http://en.wikipedia.org/wiki/ Transmission_Control_Protocol [ ^ ]。



-SA


I need to transfer a data between client application for both pc and android through internet.So i need one server.

From client side,i need to poll the server whether it has data from another client.
If it has,i need to connect to server to retrieve the data.

For this i planned to use sockets because i can able to transfer lot of data in a single connection.

First i planned to use PHP sockets,But PHP sockets allow only one request at a time.
So then i planned to use Java Custom Server Application with SSL Socket.

To setup the server,i'm going to get VPS and execute the Java application in that vps.

Is this best idea?

解决方案

Please see my comments to the question.

Not only client per thread is too much, it is, at the same time, not enough. Server side needs at least two communication thread for two different purposes: one listens for new connection, another one sending/receiving data. Please see my past answers:
an amateur question in socket programming[^],
Multple clients from same port Number[^],
How Do I Get To Know If A A Tcp Connection Is Over[^].

Also, you mentioned "poll the server". Why polling the server "for any request"? The meaning of request is different; this is something which can be done at any time. But if you really need polling (to get to the moment of time when some activity is completed, typically), this is another bad idea. You need to understand that client-server model is a very bad, limiting model. Please see my past answer:Application 'dashboard' for website accounts[^].

Now, the bright side is: with sockets, you are not limited by the client-server. The server push mentioned in the post post referenced above can be easily implemented. For example, you can implement application-layer protocol implementing published-subscriber or its combination with client-server, or anything like that. Just note that you always implement some application-level protocol on top of the transport-layer protocol, even if you don't call it a protocol. So, it's better not to pretend you don't and do it explicitly. Naturally, this application-layer will be custom for a custom service (I would prefer call it "service", not "server" to avoid suggestive naming referring to pure client-server.) Please see:
http://en.wikipedia.org/wiki/Application_layer[^],
http://en.wikipedia.org/wiki/Transport_layer[^],
http://en.wikipedia.org/wiki/Transmission_Control_Protocol[^].

—SA


这篇关于最好的想法是使用自定义服务器应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆