通过wifi为Android设备的Udp和Tcp通信

编程入门 行业动态 更新时间:2024-10-28 10:27:31
本文介绍了通过wifi为Android设备的Udp和Tcp通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 一个房间里有十个或更多的Android设备。其中一人开始向其他人广播他的名字和IP地址。 其他设备接收它并向第一个设备发送其名称和IP地址。第一个设备逐个接收名称和IP地址,并向它们发送一个字符串。这种情况可能是循环的。 我经常搜索并找到TCP和UDP协议。但UDP不可靠,速度快,对广播有用,TCP可靠,速度慢,对单播有用。 现在我决定用UDP做第一步(由其中一个设备广播),之后检测IP地址使TCP通信。 这是正确的工作吗?我可以这样做吗? 谢谢你

Hello, There are ten android devices or more in a room. One of them begins to broadcast his name and IP address to other. Other devices receive it and send to first device their names and their IP addresses. The first device receives names and IP addresses one by one and sends them a string. This scenario may be loop. I search a lot and find TCP and UDP protocols for doing it. But UDP is unreliable, speedier, useful for broadcast, and TCP is reliable, slower, useful for unicast. Now I decide to do first step(broadcast by one of the devices) with UDP, and after detecting IP addresses make TCP communication. Is that a correct work? Can I do it? Thanks

推荐答案

你在使用TCP(或UDP,这是一种无连接协议,类似于TCP)而感到困惑和网络拓扑,在你的情况下响铃也许。 在这种情况下,我会建议你不要写这样的东西。相反,我建议您为TCP客户端创建服务器并让它与网络通信。通过您的本地网络,从路由器。该服务器将侦听来自客户端的每条消息,客户端将通过网络在服务器上共享其数据。然后,您可以为每个客户端生成响应。 第一步是熟悉用Java联网 [ ^ ]。 Android使用Java作为官方编程语言,因此用Java编写的程序在Android中可以公平运行,并且根据Android标准进行一些更改。 在Android中,这些关于网络的资源可以帮助您开始通过WiFi和其他媒介进行数据共享。 developer.android/training/building-connectivity.html [ ^ ] You are confusing yourself with TCP (or UDP which is a connectionless protocol, similar to TCP) and network topology, ring in your case maybe. I would, in this case, suggest that you do not write such a thing. Instead, I would recommend that you create a server for TCP clients and let it communicate with the network. Through your local network, from the router. That server would listen to every message from the clients, client would share their data on the server through network. Then you can generate a response for each of the client. First step is to get familiar with networking in Java[^]. Android uses Java as official programming language, thus a program written in Java would work fair in Android with a few changes as per Android standards. In Android, these resources about networking can help you getting started for communicating through WiFi and other mediums for data sharing. developer.android/training/building-connectivity.html[^]

更多推荐

通过wifi为Android设备的Udp和Tcp通信

本文发布于:2023-11-23 14:28:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621779.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通信   设备   Android   wifi   Udp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!