Política de Privacidade

  Revisão 07/2023 CONDIÇÕES E TERMOS DE SERVIÇO E UTILIZAÇÃO “Intelligence Software” A Intelligence Software provê serviços de desenvolvimento de aplicativos no território brasileiro. Temos a responsabilidade de proteger cada cliente e lhes proporcionar os melhores serviços possíveis. As diretrizes seguintes foram projetadas para assegurar a qualidade de nossos serviços. Tenha certeza de que entendeu e concorda com as políticas, pois a violação dessas políticas poderá resultar em suspensão ou término da sua conta sem direito a reembolso de valores pagos. Você confirma e concorda que a Intelligence Software, a seu absoluto e exclusivo critério, pode alterar ou modificar este Acordo, e quaisquer políticas ou acordos integrados a ele, a qualquer momento, e tais alterações ou modificações entrarão em vigor imediatamente após a publicação neste Site, e seu uso deste Site ou dos Serviços encontrados neste Site após tais alterações ou modificações terem...

Simple network application - Kurose

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

 

Comentários

Postagens mais visitadas deste blog

Política de Privacidade

List of features to be realized in Packet Tracer

Cloud Native Patterns - Revisão do livro