jagomart
digital resources
picture1_Python Network Programming Pdf 196759 | Progres2015 Cours2


 171x       Filetype PDF       File size 0.35 MB       Source: www-npa.lip6.fr


File: Python Network Programming Pdf 196759 | Progres2015 Cours2
network programming with python ipv4 and ipv6 sebastien tixeuil sebastien tixeuil lip6 fr ipv4 names ipv4 names from socket import from socket import postetixeuil4 rsr lip6 fr print gethostname print ...

icon picture PDF Filetype PDF | Posted on 07 Feb 2023 | 2 years ago
Partial capture of text on file.
                          Network Programming 
                                           with Python                                                                                              IPv4 and IPv6
                                                   Sébastien Tixeuil 
                                              sebastien.Tixeuil@lip6.fr
                                           IPv4 Names                                                                                                  IPv4 Names
                        from socket import *                                                                                        from socket import *                    postetixeuil4.rsr.lip6.fr
                        print(gethostname())                                                                                        print(gethostname())
                                                                                                                                                                            postetixeuil4.rsr.lip6.fr
                        print(getfqdn())                                                                                            print(getfqdn())
                                                                                                                                                                            132.227.104.15
                        print(gethostbyname('lip6.fr'))                                                                             print(gethostbyname('lip6.fr'))
                        print(gethostbyaddr('132.227.104.15'))                                                                      print(gethostbyaddr('132.227.104.15'))  ('ww.lip6.fr', ['15.104.227.132.in-
                                                                                                                                                                            addr.arpa'], ['132.227.104.15'])
                        print(gethostbyname(getfqdn()))                                                                             print(gethostbyname(getfqdn()))         132.227.84.244
                            IPv4-IPv6 Names                                                                       IPv4-IPv6 Names
                   infolist = getaddrinfo('lip6.fr','www')                                               infolist = getaddrinfo('lip6.fr','www')
                   print(infolist)                                                                       print(infolist)                [(, 
                                                                                                                                       , 17, 
                                                                                                                                         '', ('132.227.104.15', 80)), 
                   info = infolist[1]                                                                    info = infolist[1]              (, 
                                                                                                                                       , 6, 
                                                                                                                                         '', ('132.227.104.15', 80))]
                   print(info)                                                                           print(info)
                                                                                                                                         (, 
                   s = socket(*info[0:3])                                                                s = socket(*info[0:3])        , 6, 
                                                                                                                                         '', ('132.227.104.15', 80))
                   s.connect(info[4])                                                                    s.connect(info[4])
                                                                                                                  Strings vs. Bytes
                                                                                                         • Strings are meant for general Unicode support 
                           Strings and Bytes                                                             • Bytes are what is sent/received through the network 
                                                                                                         • Encoding of Strings into Bytes before sending 
                                                                                                           toSend = str.encode(‘utf-8’)
                                                                                                         • Decoding Bytes into Strings when receiving 
                                                                                                           str = received.decode(‘utf-8’)
                    UDP Python Client                                               UDP Python Server
              from socket import *                                             from socket import *
              serverName = ‘A.B.C.D’                                           serverPort = 1234
              serverPort = 1234                                                serverSocket = socket(AF_INET,SOCK_DGRAM)
              clientSocket = socket(AF_INET,SOCK_DGRAM)                        serverSocket.bind((‘’,serverPort))
              message = input(‘lowercase sentence:’).encode(‘utf-8’)           print(‘server ready’)
              clientSocket.sendto(message,(serverName,serverPort))             while True:
              modifiedMessage, serverAddress = clientSocket.recvfrom(2048)      message, clientAddress = serverSocket.recvfrom(2048)
                                                                                modifiedMessage = message.decode(‘utf-8’).upper()
              print(modifiedMessage.decode(‘utf-8’))                            serverSocket.sendto(modifiedMessage.encode(‘utf-8’), 
              clientSocket.close()                                              clientAddress)
                                                                               Byte Order over the Network
                                                                               from struct import *
                        Numbers and                                            print(hex(1234))
                                                                               print(pack('i',1234))
                                                                               print(pack('!i',1234))
                                                                               print(unpack('>i',b'\x00\x00\x04\xd2'))
                                                                               print(unpack('!i',b'\x00\x00\x04\xd2'))
                   Byte Order over the Network
                   from struct import *
                   print(hex(1234))                                0x4d2
                   print(pack('i',1234))
                   print(pack('!i',1234))                   b'\x00\x00\x04\xd2'
                                                                  (1234,)
                   print(unpack('>i',b'\x00\x00\x04\xd2'))        (1234,)
                   print(unpack('!i',b'\x00\x00\x04\xd2'))
                        Network Exceptions                                                                    Network Exceptions
                                                                                                         from socket import *
                   • OSError: almost every failure that can happen 
                     during a network connection                                                         try:
                   • socket.gaierror: address-related error                                                  infolist = getaddrinfo('nonexistent.com','www')
                   • socket.timeout: timeout expired                                                     except gaierror:
                                                                                                             print("This host does not seem to exist")
The words contained in this file might help you see if this file matches what you are looking for:

...Network programming with python ipv and sebastien tixeuil lip fr names from socket import postetixeuil rsr print gethostname getfqdn gethostbyname gethostbyaddr ww infolist getaddrinfo www info s connect strings vs bytes are meant for general unicode support what is sent received through the encoding of into before sending tosend str encode utf decoding when receiving decode udp client server servername a b c d serverport serversocket af inet sock dgram clientsocket bind message input lowercase sentence ready sendto while true modifiedmessage serveraddress recvfrom clientaddress upper close byte order over struct numbers hex pack i unpack x xd exceptions oserror almost every failure that can happen during connection try gaierror address related error nonexistent com timeout expired except this host does not seem to exist...

no reviews yet
Please Login to review.