在Android中使用UDP和MQTT协议编写聊天程序 [英] To write chat programming using UDP and MQTT protocol in Android

查看:450
本文介绍了在Android中使用UDP和MQTT协议编写聊天程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android编程的新手,不知道如何在android设备中使用UDP和MQTT协议

I am new in Android programming and don't know how to work with UDP and MQTT protocol in android device

我想构建一个用于将android聊天到连接到同一Wi-Fi路由器的房间内的android设备的应用程序.

I want to build an application for chatting android to android device within room connected to same Wi-Fi router.

但是我不知道应该将哪些IP地址和端口绑定到DatagramSocket和DatagramPacket.

But I don't know what IP address and port I should bind to DatagramSocket and DatagramPacket.

我从网上尝试了很多示例,但我不知道它如何在android中工作.

I tried lot of examples from online but I didn't understand how it will work in android.

推荐答案

MQTT需要TCP,它是一个全状态协议,您不能使用UDP来实现

MQTT requires TCP, it is a statefull protocol, you can not implement it with UDP

有一个类似的协议,称为 MQTT- SN 可以通过UDP等无状态协议来实现.

There is a similar protocol called MQTT-SN which can be implemented with a stateless protocol like UDP.

但这两个都仍然需要在某个地方运行的代理来协调将消息传递给给定主题的订户

But both of these are still going to require a broker running somewhere to coordinate the delivery of messages to subscribers to given topics

这篇关于在Android中使用UDP和MQTT协议编写聊天程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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