Can I use the UDP protocol to implement the communications between two directly connected PCs?
Yes, you can.
The only downfall could be you can't be sure of proper delivery of messages(as in case of TCP).
You'll need to develop a very good application layer code, which would kind of mimic the functionalities of TCP , to achieve a reliable communication.
Related
I am studding the MQTT & TCP/IP protocol.
Since i'm able to know that, MQTT is based on the TCP so as the TCP/IP
& we refer MQTT though we have the TCP/IP Protocol.
Why don't we use TCP/IP instead of MQTT?
Is there any advantages of MQTT that makes it better solution than the TCP/IP protocol?
Which is more reliable & required less no of data packet to form a communication?
(Note : TCP/IP in the sense forming a network between 2 devices using normal TCP/IP protocol as in GSM modems "connect > transfer data > disconnect")
Is there any advantages of MQTT that makes it better solution than the TCP/IP protocol?
Yes, it offers things TCP doesn't offer, namely an application layer protocol. Other examples of such protocols are FTP, HTTP, SMTP.
You're asking the wrong question. IP makes sure you can send data to another machine, TCP makes sure this data is received in-order and acknowledged, and application-level protocols make sure you can make sense of the data you receive.
Without an application level protocol, you have no meaningful communication. Where each sockets programming example begins with "WriteLine" and "ReadLine" text message exchanges, that in itself is (albeit a very rudimentary) application level protocol, namely "client and server exchange text messages ending in a newline".
So, no, you cannot use TCP/IP without an application level protocol, because as soon as you start writing a program sending and/or receiving data, you have at that moment defined an application level protocol.
With its own problems. And that's why you shouldn't invent your own protocol, but use existing ones. Pick the one that suits your needs. Do you need to publish or subscribe messages to some broker, use MQTT.
Unless you know very well what you're doing, don't invent your own.
The benefits of using MQTT over TCP/IP far outweighs the data overhead it introduces. Also, MQTT was devised to solve a specific problem of getting sensor data from a remote system which could not be connected to the consumer of the sensor data all the time.
I'm currently developping a highly responsive game in python using client-server model. The speed of the data exchanges between the client and the server needs to be very fast.
Is it possible to make both, udp and tcp connections ? Udp would be used only during the game. And Tcp will be used for more reliability-needed messages like connection, name changes, chat,...
Is it also a good way of thinking ? Or should i use only UDP ?
Yes, this can be a good idea. With UDP, a single lost packet does not stall the entire stream. On the other hand you need retry and congestion control.
I'd try to send messages using UDP and if no confirmation arrives within a short amount of time re-send them on a TCP connection that has been kept open. That should move 99% of the load to UDP and use TCP for congestion control and reliability.
The H2O database does it that way.
You can bind your UDP and TCP connections on different ports or even on the same port. As for which to use, it is up to you. Try both out and if TCP is too slow or UDP is too unreliable then you always have the option to switch.
You can also use a 3rd-party library that builds reliability layer over UDP and specify required reliability per packet. As an example you can check Raknet.
In my current semester, I am studying the course of communications and networks. My teacher gave us an assignment to choose the best protocol for three different scenarios. I am new to this course, and I am not 100% sure. Please help me to solve this. Here is the question.
Assume you have two users A and B, who want to communicate with each other over a communication network. The applications they are using for this purpose can either make use of TCP or UDP protocol. Explain which of these protocols (TCP and UDP) will be the best to use in the following circumstances and why?
a) Both A and B want to send chat messages to each other.
b) Both A and B wants to do a voice conversation.
c) A wants to send a file of size 5MB to B.
hi for that above requirement you can done any one of the protocols. i thing both will work fine nicely. the decision on yours the tcp protocol used for connection oriented network that is more secure than udp. mostly udp is used for connection less network. u can able to do the above on the both protocol.
Since the MQTT protocol flows over TCP the difference between the three QoS levels is quite subtle. In normal conditions TCP will ensure delivery and prevent duplicates.
I intend to use MQTT to send real-time data to mobile devices, but I don't need reliable delivery. Keeping battery consumption as low as possible is really important, so it would be great to avoid sending unnecessary messages (TCP's acknowledgements).
Would it be possible to implement MQTT over UDP, or other unreliable transport layer protocol? Is there any existing library doing this?
MQTT-S can run over UDP, but there aren't any publicly available libraries for it yet. Are you sure the battery usage is that much of a problem? There is a run down of some experiments done on MQTT power usage on Android at http://stephendnicholas.com/archives/219
I think that MQTT itself really makes use of the TCP delivery and ordering guarantees. I believe it would be very difficult to guarantee it working over UDP.
Could i inject packets to Linux TCP stack without modifying the ethernet driver? Could i do this with using a library or sth ?
Thank you,
If by 'inject packets to Linux TCP stack' you mean send some data that the Linux kernel will treat as a frame coming from an Ethernet interface then you can use a 'tap' device. If an IP packet (layer 3) is good enough, then use a 'tun' device.
http://en.wikipedia.org/wiki/TUN/TAP
http://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/Documentation/networking/tuntap.txt
Libnet
Libnet is a generic networking API that provides access to several protocols. It is not designed as a 'all in one' solution to networking. Currently many features that are common in some network protocols are not available with Libnet, such as streaming via TCP/IP. We feel that Libnet should not provide specific features that are possible in other protocols. If we restrict Libnet to the minimal needed to communicate (datagram/packets) then this allows it to support more interfaces.
Otherwise, if you're just wondering about injecting hand-crafted packets into the network, read the man pages and look for online help with raw sockets. Some good places to start are man 7 raw, man packet, and there are some ok tutorials at security-freak.net, though the code there is not written particularly well for my tastes.