Socket Programming in ESP8266 using MicroPython

Keywords: Socket, Socket programming, TCP/UDP

 

Dictionary meaning of a Socket – an electrical device receiving a plug or light bulb to make a connection.

In computer terminology, when a computer program needs to connect to Internet, it uses a software component called a socket. The socket opens the network connection for the program, allowing data to be read and written over the network. Please note that these sockets are software networking sockets, unlike hardware sockets these sockets will not give any shock ☠ 😄.

When two computers or processes want to communicate they can do that  through Sockets. Sockets allow processes to communicate with each other ​using a file descriptor and are commonly used in client-server applications that allow ​for ​communication between multiple applications. They are used with different network protocols like HTTP, FTP, telnet, and e-mail, multiple sockets can be opened at a time.

Now hope you understood what a socket is !. Lets go ahead and understand how sockets are created and configured.

Socket = IP Address + Port Number

A Port is a communication endpoint that identifies a specific process or a type of network service. Ports are identified for each protocol and address combination by 16-bit unsigned numbers, commonly known as the Port  number. The most common protocols that use port numbers are the TCP and the UDP.

A port number is always associated with an IP address of a host and the protocol type of the communication. It completes the destination or origination network address of a message.

An Internet Protocol Address (IP address) is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. An IP address serves two main functions:

  1. Host / Network interface identification
  2. Location addressing.

So every computer is identified by using an IP Port.

Most inter-process communication uses the client server model. These terms refer to the two processes which will be communicating with each other. One of the two processes, the client, connects to the other process, the server, typically to make a request for information. A good analogy is a person who makes a phone call to another person.

The steps involved in establishing a socket on the client side are as follows:

  1. Create a socket
  2. Connect the socket to the address of the server
  3. Send and receive data

The steps involved in establishing a socket on the server side are as follows:

  1. Create a socket
  2. Bind the socket to an address on the host machine.
  3. Listen for connections
  4. Accept a connection
  5. Send and receive data

Lets understand how to download a web page using HTTP GET request in MicroPython.

Prerequisites:

  • ESP8266 hardware
  • uPyCraftIDE

This code would retrieve the webpage and print the HTML code to the console in pyCraftIDE.

Hope you understood how to configure sockets using HTTP connection. Next posts would be on TCP and UDP socket connections.

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.😄

Related posts

One Thought to “Socket Programming in ESP8266 using MicroPython”

  1. […] to🤔socket programming. There are two widely used Socket types, stream sockets, and datagram sockets. Stream sockets […]

Leave a comment....