-
Notifications
You must be signed in to change notification settings - Fork 7
Session 9: Practice 2
- Time: 2h
- Date: Wednesday, Feb-26th-2020
-
Goals:
- Practicing with the creation of clients
- More Practicing on creating classes and objects
- Learn how to run servers and clients on the same machine
- Get familiar with the typical socket and network errors that will occur
The goal of this practice is to gain experience running servers and clients in the same computer. We will develop python programs (clients) that send messages and sequences to other servers
For making it easier to send the messages, we will develop the class Client located in the Client0 module (File Client0.py)
Method | Parameters | Return | Description |
---|---|---|---|
__init__(ip, port) | IP: String, Port: Integer | None | Object Constructor. Stores the IP and Port values inside the object |
__str__() | none | String | It returns the string: "Connection to SERVER at {ip}, PORT: {port}", where the {ip} and {port} are the server's ip and port respectivelly |
ping() | None | None | It prints the "OK" message on the console. It is just for testing the module |
talk(msg) | msg: String to send to the server | The response message from the server | It creates a new socket, connects to the server, sends the message, receive the response message from the server and closes the socket |
debug_talk(msg) | msg: String to send to the server | The response message from the server | It works the same than the talk method, but it prints on the console both the message sent to the server and the response received, in different colors |
As always, this class will be created step by step in the exercises. The process is guided
We will implement the Client Class and develop some example programs to test it against the server
Let's start writing the Client Class. Create the file P2/Client0.py. Implement the __init__() and the ping() methods. Do not forget to mark the P2 folder as Sources Root
- Filename: P2/Client0.py
- Description: Class for sending messages easily to the server
Create the EX1.py File for testing the Client Class. It just creates a client object, calls the ping() method and prints the configured IP and PORT.
- Filename: P2/EX1.py
- Description: Preliminary test of the Client Class
The code should looks like this:
from Client0 import Client
PRACTICE = 2
EXERCISE = 1
print(f"-----| Practice {PRACTICE}, Exercise {EXERCISE} |------")
# -- Parameters of the server to talk to
IP = "192.168.1.45"
PORT = 8080
# -- Create a client object
c = Client(IP, PORT)
# -- Test the ping method
c.ping()
# -- Print the IP and PORTs
print(f"IP: {c.ip}, {c.port}")
When executed, this is what you should see (but with different values of the IP and PORT):
-----| Practice 2, Exercise 1 |------
OK!
IP: 192.168.1.45, 8080
Process finished with exit code 0
- Open a sequence from a file (ADA or whatever), calculate its complement, divide it into pieces of 20 bases and send to the server....
- Open all the genes and send them to the server
- Launch two servers. Open a gene. Read 20 bases. If the initial base is 'A' or 'T' is sent to the server 1, if the base is 'C' or 'G' it is sent to the other server
The session is finished. Make sure, during this week, that everything in this list is checked!
- You have all the items of the session 6 checked!
- Your working repo contains the P1 Folder with the following files:
- Ex1.py
- Ex2.py
- Ex3.py
- Ex4.py
- Ex5.py
- Ex6.py
- Ex7.py
- Ex8.py
- Ex9.py
- Ex10.py
- Seq0.py
- All the previous files have been pushed to your remote Github repo
- Juan González-Gómez (Obijuan)
- Alvaro del Castillo. He designed and created the original content of this subject. Thanks a lot :-)
S0: Introduction
S1: Tools I
S2: Tools II
S3: Practicing with the tools
S8: Client-Server-1
S9: Client-Server-2
S10: Client-server-3
S11: Client-server-4
S12: HTTP protocol-1
S13: HTTP protocol-2
S14: HTTP module
S15: HTTP module
S16: HTML forms
S17: HTML forms