简体   繁体   English

在Android Java中从Socket发送和接收

[英]Send and receive from Socket in Android Java

Hi All I have a small question. 大家好我有一个小问题。

  • I have server client application Where the client will be sending data asynchronously. 我有服务器客户端应用程序,其中客户端将异步发送数据。
  • The server will receive message and parse. 服务器将接收消息并进行解析。
  • If server receives a wrong data it will send and error message to the client. 如果服务器收到错误的数据,它将向客户端发送错误消息。

Now my Problem is in client I will be sending data continuously with out caring about acknowledgement example: 现在我的问题是在客户端中,我将继续发送数据而无需关心确认示例:

  • Suppose I am sending some 1000 messages from client. 假设我从客户端发送了大约1000条消息。 The client sends all the data in the socket. 客户端发送套接字中的所有数据。
  • If error occurs server will also put error message in the socket. 如果发生错误,服务器也会在套接字中插入错误消息。
  • But either one can happen: send data from client or send message from the server. 但是任何一种都可能发生:从客户端发送数据或从服务器发送消息。

    What is the best way to handle the case? 处理案件的最佳方法是什么?

If any error occurs and client receives the error message from the server then the client has to resend the data. 如果发生任何错误,并且客户端从服务器接收到错误消息,则客户端必须重新发送数据。 One way is to send the data and wait for acknowledgement. 一种方法是发送数据并等待确认。 I don't want client to wait for servers ack because chances of error are very less. 我不希望客户端等待服务器确认,因为出错的机会非常少。 Can any one tell me some good solution to this? 谁能告诉我一些好的解决方案?

使错误消息包含客户端应重新开始发送的“索引”。

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

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