jagomart
digital resources
picture1_Python Network Programming Pdf 192706 | Python Cheat Sheet


 139x       Filetype PDF       File size 0.07 MB       Source: gencyber.ialab.dsu.edu


File: Python Network Programming Pdf 192706 | Python Cheat Sheet
python network programming cheat sheet python hints mystring this is a string this example shows how to declare a string mynumber 432 this example shows how to declare a number ...

icon picture PDF Filetype PDF | Posted on 05 Feb 2023 | 2 years ago
Partial capture of text on file.
        Python Network Programming
                   Cheat Sheet
     Python Hints
     myString = 'this is a string.' 
     This example shows how to declare a string.
     myNumber  = 432
     This example shows how to declare a number.
     MyBool = True
     This example shows you how to declare a boolean value like True or False. Notice there's no single or 
     double quotes?
     myList = ['string 1','string 2',53,42]
     This example shows how to declare a list containing two strings, and two numbers.
     myList[0]
     Piggybacking on the example above, myList[0] would print 'string 1'. This is because it is the 0 index 
     of the list. MyList[1] would print 'string 2', and so on.
     “”” Check out my long
     comment!!!
     “””
     3 quotation marks opens a comment block and 3 quotation marks closes them. Use this to document 
     your code! This is a very useful technique so you understand what your code is doing. Additionally yo 
     u may use a # sign to comment.
     Socket Library Hints
     Review the socket library documentation here! 
     Https://docs.python.org/2/library/socket.html
     import socket: Enhances your script with socket communication capabilities. This line needs to be at 
     the top of your script to make sure it can be used.
     socket.gethostbyname(string): Pass a hostname as a string like 'dsu.edu' into this method to have the 
     socket library resolve the domain name dsu.edu into an IP address.
     socket.gethostbyaddr(string): Pass an IP address as a string like '138.247.65.57' into this method to 
     have the socket library find the hostname  for the IP address.
     socket.socket(address_type, protocol_type): Use this method to define a socket object. Is is important 
     to define the address type, and the protocol to be used for communication. An example to define an 
     IPv4 TCP socket would be: myTCPSocket = 
     socket.socket(socket.AF_INET,socket.SOCK_STREAM)  
     myTCPSocket.connect((ip_address,port_number)): piggybacking off of the above example. Once 
     you have defined what type of socket you want to utilize, you need to connect to the destination. Here, 
     you pass the ip_address and port_number together as a pair to connect. The (( and )) are not typos and 
     you must type this to successfully connect. A working example to connect to the DSU.EDU Webserver 
     would be: myTCPSocket.connect(('138.247.65.57',80))
     myTCPSocket.sendall(string): piggybacking off of the above example. Once the 
     myTCPSocket.connect() method has been called, you can now send any string you want through the 
     socket. This literally means you are sending data to the other machine!!! A working example of this 
     would be: myTCPSocket.sendall('Is anyone there?')
     myTCPSocket.recv(#ofdatapackets): piggybacking off of the above example. Once the 
     myTCPSocket.sendall() method succeeds, you now have the opportunity to capture what message is 
     sent back from the destination. Make sure that the #ofdatapackets is a number between 1 and 65535 A 
     working example of this would be:  receivedData = myTCPSocket.recv(1024)
     socket.AF_INET (IPv4), socket.AF_INET6 (Ipv6): The common values used in socket.socket() 
     method for the address_type variable.
     socket.SOCK_STREAM (TCP), socket.SOCK_DGRAM (UDP), socket.SOCK_RAW (Special): 
     The common values used in the socket.socket() method for the protocol_type variable.
The words contained in this file might help you see if this file matches what you are looking for:

...Python network programming cheat sheet hints mystring this is a string example shows how to declare mynumber number mybool true you boolean value like or false notice there s no single double quotes mylist list containing two strings and numbers piggybacking on the above would print because it index of so check out my long comment quotation marks opens block closes them use document your code very useful technique understand what doing additionally yo u may sign socket library review documentation here https docs org html import enhances script with communication capabilities line needs be at top make sure can used gethostbyname pass hostname as dsu edu into method have resolve domain name an ip address gethostbyaddr find for type protocol define object important ipv tcp mytcpsocket af inet sock stream connect port off once defined want utilize need destination together pair are not typos must successfully working webserver sendall has been called now send any through literally means s...

no reviews yet
Please Login to review.