1.Network Programming (Introduction About TCP-IP)(1)
1.Network Programming (Introduction About TCP-IP)(1)
INTRODUCTION TO NETWORK
PROGRAMMING
Computer System
Computer Network
Layering
TCP/IP layering
1
Computer system
➢ The users of a system communicate with the hardware of the system.
➢ The communication can't be direct i.e. a user can't directly give instructions to the
hardware to perform various operations because it is very difficult for the user to
convert its request or instruction into machine language.
➢ An Operating System
➢ It is a software that acts as an intermediate between the hardware and the user.
➢ It is a kind of resource manager that manages both hardware and software resources
of a system.
➢ It control and coordinate the hardware to execute an application required by users.
• Because this reliable flow of data is provided by the transport layer, the
application layer can ignore all these details.
There is a use for each type of transport protocol, which we’ll see
when we look at the different applications that use TCP and UDP.
FTP
server
➢ The application layer and the transport layer use end-to-end protocols and are
needed only on the end systems.
➢ The network layer, however, provides a hop-by-hop protocol and is used on the
two end systems and every intermediate system.
✓ The network layer, IP, provides an unreliable service. It does its best job of
moving a packet from its source to its final destination, but there are no
guarantees.
✓ The transport layer, TCP, provides a reliable transport layer using the unreliable
service of IP. To provide this service, TCP performs timeout and retransmission.
➢ In this case we can call the system either a host (when an application such as
FTP or Telnet is being used) or a router (when it’s forwarding packets from one
network to another).
➢ One of the goals of an Internet is to hide all the details of the physical layout of
the Internet from the applications. It is obvious from the two network layers in
Figure 2.5 that the application layers don’t care that one host is on an Ethernet,
the other on a token ring or any type of physical interconnections, with a router
between them or many routers. The applications would run the same.
➢ This hiding of the details is what makes the concept of an Internet so powerful
and useful.
➢ Another way to connect networks is with a bridge. These connect networks at
the link layer, while routers connect networks at the network layer. Bridges
makes multiple LANs appear to the upper layers as a single LAN.
➢ Print
print("Hello, World!")
Hello, World!
➢ Comment syntax
# This is a comment for one line
"""
This is a comment
written in
more than just one line (put between triple quotes)
""“
➢ Variables
• A variable is created the moment you first assign a value to it.
• Variables do not need to be declared with any particular type, and can even
change type after they have been set.
y = 5.24568
y = int(y)
print(y) 5
➢ Output Variables
x = "awesome"
print("Python is " + x) Python is awesome
x = "Python is "
y = "awesome"
z= x+y
print(z) Python is awesome
x=5
y = 10
print(x + y) 15
If you try to combine a string and a number, Python will give you an error.
Dr. Elhossiny Ibrahim 16 4th year: network programming
Python User Input
➢ Python User Input
• This means we are able to ask the user for input, it gets printed on the screen.
The value entered is always string.
username = input("Enter username:") Enter username: ahmed
print("Username is: " + username) Username is: ahmed
print(“The user age is: ", userage) The user age is: 20
➢ String format()
• allows you to format selected parts of a string.
price = 49
print("The price is {} dollars". format(price))
The price is 49 dollars
• Multiple values
quantity = 3
price = 49
print("I want {} pieces for {}dollars.". format(quantity, price))
I want 3 pieces for 49 dollars.
Dr. Elhossiny Ibrahim 17 4th year: network programming
Python List
➢ Strings are Arrays
a = "Hello, World!“
print(a[0]) H
print(a[3]) L
13
print(len(a)) # length of characters and space
➢ Python List
• Lists are used to store multiple items in a single variable.
• A list is a collection which is ordered and changeable (mutable).
thislist = ["apple", "banana", "cherry"]
print(thislist)
["apple", "banana", "cherry"]
print(thislist[1])
apple
➢ Append Items: To add an item to the end of the list
thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
["apple", "banana", "cherry“, "orange")]
Dr. Elhossiny Ibrahim 18 4th year: network programming
Python tuples
➢ Python tuples
• Tuples are used to store multiple items in a single variable.
• A tuple is a collection which is ordered and unchangeable (immutable).
thistuple = ("apple", "banana", "cherry")
print(thistuple)
("apple", "banana", "cherry“)
➢ Change tuple values
x = ("apple", "banana", "cherry")
x = list(x)
x[1] = "kiwi" % change the second item
x.append("orange")
x = tuple(x)
print(x)
("apple", “kiwi", "cherry“, "orange")