March 2019
Beginner
490 pages
12h 40m
English
We are going to write a program that defines a client that opens the connection in a given port and host. This is very simple to do with the socket.connect (hostname, port) function, which opens a TCP connection to the hostname on the port. Once we have opened an object socket, we can read and write this in as any other object of input and output (I/O), always remembering to close it as we close files after working with them.
You can find the following code in the tcp_client.py file:
#!/usr/bin/env python3import socket# The client must have the same server specificationshost = '127.0.0.1'port = 12345BUFFER_SIZE = 1024MESSAGE = 'Hello world,this is my first message'with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as ...
Read now
Unlock full access