Posts

Showing posts with the label socket

Bubble sort in Python Language

Image
Bubble sort is the simplest Sorting algorithm available. It works by repeatedly swapping the adjacent or neighbor element if they are in the wrong order. Working Actually in the first-pass bubble sort sets the largest element to its position, in the second pass algorithm sets the second largest element this continues till the list or array is not finally sorted. Here is the example image. To work with the algorithm you first have to understand what is swapping and how it is done. What is Swapping ?? Swapping is a technique to interchange the content of the two variables, using another variable called a temporary variable. In python programming language swapping works in two ways, both of them are shown below. For the program in Python arr = [64, 34, 25, 12, 22, 11, 90] n = len(arr) for i in range(n): # Last i elements are already in place for j in range(0, n-i-1): # traverse the array from 0 to n-i-1 # Swap if the element found is greater # than the next element if

TCP Socket Programming in Python (server/client)

Image
Socket Programming in Python What is Socket :  A  socket  is one end of a two-way communication link between two programs/software running on the network. A socket is bound to a port (also known as process id) number so that the TCP/UDP layer can identify the application that data to be transferred to. What to do? in order to create a server first, we need to create a socket in the program and put this socket into the listen mode. to that in the python is very easy, as you all know python is a very easy and powerful language. Socket Creation Create a New python file named as the server.py keep in mind that to work with socket we need to import socket into the file. import socket TCP_IP = '127.0.0.1' TCP_PORT = 15710 s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.bind((TCP_IP,TCP_PORT)) TCP_IP is the IP of this machine you are working on, and TCP_PORT is the port to be connected. socket.AF_INET is the protocol to work with the TCP protocol. Listening to connection and a