简体   繁体   English

是否可以使用TCP套接字将JSON数据从Java服务器发送到Android客户端

[英]Is it possible to send json data from java server to android client using TCP sockets

I want to develop a app, where user is automatically updated about new stories, just like facebook where it shows new stories at the top. 我想开发一个应用程序,该应用程序会自动向用户更新新故事,就像在顶部显示新故事的facebook一样。 One way for this is to keep timer and send request continously. 一种方法是保持计时器并连续发送请求。 But I want to send data from server to android client using TCP socket connection. 但是我想使用TCP套接字连接将数据从服务器发送到android客户端。 I refered few links about how to establish a socket connection between two android devices. 我引用了一些有关如何在两个android设备之间建立套接字连接的链接。 But they are sending just a plain text and server requires a response from the client, only then it sends the next data. 但是他们只发送纯文本,服务器需要客户端的响应,然后才发送下一个数据。 But I want to continously send json data to the client. 但是我想不断地将json数据发送到客户端。 Is it possible to send json data continously from web server to android client, without getting response from client? 是否有可能从Web服务器连续向android客户端发送json数据,而没有客户端的响应?

Why don't you use WebSocket ? 为什么不使用WebSocket It's a bidirectional TCP connection through which you can send text and/or binary messages. 这是双向TCP连接,您可以通过它发送文本和/或二进制消息。

To use WebSocket, you have to use a web server that supports WebSocket ( Tyrus , Jetty , ...) and a WebSocket client library on Android side ( nv-websocket-client , ...). 要使用WebSocket,您必须使用支持WebSocket的Web服务器( TyrusJetty等)和Android端的WebSocket客户端库( nv-websocket-client ,...)。

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

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