Sunday, May 17, 2020

Interview Questions related to Networking in Python and and Basic concepts to remember


I am trying to capture all possible questions that can be asked during python networking questions for core-python developers. It is very basic but very important. Good product based companies ask these types of questions in good interviews and I think we all should at least aware of these things.

  • The interconnection of computer is called Network.
  • The advantage of a network is sharing resources like data, files, software, and hardware.
  • The computers which receive data from a network are called clients and computers which provide services are called severs.
  • A protocol represents a set of rules to be followed by every computer on the network. So there are two protocol models are TCP/IP and UDP. All other protocols are developed based on these two protocols.
  • TCP/IP is a connection-oriented protocol that transmits data safely.
  • UDP is a connectionless protocol and may not transmits data safely.
  • An IP address is a unique identification number given to every computer on the network. It contains four integers numbers in the range of 0 to 255 and separated by a dot. 
  • A socket is a logical point of connection between a server and a client. Data is transmitted through sockets only.
  • Every socket is identified with a unique number called port number.
  • Port number is a 2byte number and ranges from 0 to 65535.
  • A socket with a constant socket.SOCKET_STREAM is created to work with TCP/IP protocol.
  • A socket with a constant socket.SOCK_DGRAM is created to transmit data on UDP protocol.
  • The gethostbyname() function of a socket module is used to find the IP Address of any website.
  • The messages are transmitted between the server and the client in the form of binary strings.
  • The encode() method converts a normal string into a binary string and decodes () method converts a byte stream into a normal string.
  • SMTP class of smtplib module and MIMEText class of email.mimime.text module are provided in python to send emails on the internet.
Sample program to Send an Email:

import smtplib

body = ''' This is my text mail.this is sent to you because I am teaching Python.'''

msg=MIMEText(body)

fromaddr="abhinawtripathi34@gmail.com"
toaddr="abhinawtripathi@ymail.com"

msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "hi friend!"

server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()

server.login(fromaddr,"MyPassword")
sever.send_message(msg)
print('Mail sent...')
server.quit()

Output: 
      
   C\:>python mail.python
   Mail sent...

While running this program we should be connected with the internet. This program is sending the mail through gmail.com sever





No comments: