Simple network application - Kurose
- Gerar link
- X
- Outros aplicativos
Kurose's book of the 6th edition in its chapter 2 dealing with transport layer protocols has a really cool exercise that is an example of how to program a network application. The application is very simple, there is a server that will run on one machine and a client on another, the client sends a message in lowercase to the server and then receives the same message in uppercase, this is the client code "UDPClient. py", since it's an old Python application it had some minor syntax tweaks:
import socket
serverName = 'ubuntuteste'
serverPort = 12000
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
message = input('Insira uma sentenca em letras minusculas: ')
clientSocket.sendto(message.encode(),(serverName, serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
print (modifiedMessage)
clientSocket.close()
This is the server code, "UDPServer.py":
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('', serverPort))
print ("Servidor pronto para receber")
while 1:
message, clientAddress = serverSocket.recvfrom(2048)
modifiedMessage = message.upper()
serverSocket.sendto(modifiedMessage, clientAddress)
I added the server name "serverName" from UDPClient.py to /etc/hosts on my machine, here are some screenshots of the test performed:
Server:
Test on client:
Finally, the application worked and with the basis given in the book you can even think about other applications, the book brings all the explanation of the code and also more exercises. Remembering that this was a test using the UDP protocol there is in the book the same test performed using TCP.
Website: https://www.intelligencesoftware.com.br
Ads: https://ads.intelligencesoftware.com.br
- Gerar link
- X
- Outros aplicativos
Comentários
Postar um comentário