Keywords: Socket, Socket programming, TCP/UDP
Continuation to🤔socket programming. There are two widely used Socket types, stream sockets, and datagram sockets. Stream sockets treat communications as a continuous stream of characters, while datagram sockets have to read entire messages at once. Each uses its own communications protocol. Stream sockets use TCP (Transmission Control Protocol), which is a reliable, stream oriented protocol, and datagram sockets use UDP (User Datagram Protocol), which is unreliable and message oriented.
TCP socket runs on top of IP (Internet Protocol). TCP is a connection-oriented communication protocol. What is this connection-oriented🤔? Connection-oriented communication is a network communication in which temporary connection must be established before any data is transferred and data stream is delivered in the same order as it was sent. I personally worked on TCP so I ‘rely’ on this protocol as it provides for the recovery of segments that get lost, are damaged, duplicated or received out of their correct order. Lets learn how to write Micropython code to download data from the internet.
TCP Applications
Here are few real-time applications of TCP
- FTP
- SMTP
- Telnet
Prerequisites:
- ESP8266 hardware
- uPyCraftIDE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
''' Author : Seetha Akella Purpose : Establishing TCP Socket on Client Language : MicroPython Hardware : ESP8266 ''' import socket import time addr = socket.getaddrinfo("muck.wintersoasis.com",8888)[0][-1] print(addr) s = socket.socket() s.connect(addr) while True: data = s.recv(500) if data: print(str(data, 'utf8'), end='') else: print ("data not received\n") break time.sleep(1) s.close() |
Here is the output of the above code.
To have more fun you can try the telnet servers to download the data.
THANK YOU and many more posts coming your way!
Please put your queries in comment section, I will get back to you with answers ASAP.
Please like and share Techawarey. Find and Like Techawarey on Facebook.😊