SlideShare a Scribd company logo
1 of 22
Download to read offline
Visual C# .Net using
framework 4.5
Eng. Mahmoud Ouf
Lecture 12
mmouf@2017
Network Architecture
mmouf@2017
Type of Communications
There are two types of communications:
• Connection oriented communications
Which are similar to the telephone system, in which a connection is
established and held for the length of the session
• Connectionless communications
Which are similar to the postal service, in which two letters mailed from
the same place and to the same destination may actually take two different
paths through the system and even arrive at different times
mmouf@2017
Communication Protocols
There are two types of protocols:
• Transmission Control Protocol (TCP)
connection-oriented communication protocol which guarantees that sent
packets will arrive at the intended receiver undamaged and in the correct
sequence.
If packets of information don't arrive at the recipient, TCP ensures that the
packets are sent again.
If the packets arrive out of order, TCP reassembles them in the correct
order transparently to the receiving application.
If duplicate packets arrive, TCP discards them.
mmouf@2017
Communication Protocols
• User Datagram Protocol (UDP)
connectionless communication protocol. It incurs the minimum overhead
necessary to communicate between applications.
UDP makes no guarantees that packets, called datagrams, will reach their
destination or arrive in their original order.
mmouf@2017
Socket Programming
mmouf@2017
Addresses and Ports
To communication with computer or device, computer requires an address.
The Internet uses two addressing systems:
IPv4 (Currently the dominant addressing system)
IPv4 addresses are 32 bits wide.
When string-formatted, IPv4 addresses are written as four dot-separated
decimals (e.g., 101.102.103.104).
An address can be unique in the world or unique within a particular subnet
(such as on a corporate network).
IPv6 (The newer 128-bit addressing system)
Addresses are string-formatted in hexadecimal with a colon separator (e.g.,
[3EA0:FFFF:198A:E4A3:4FF2:54fA:41BC:8D31]).
mmouf@2017
Addresses and Ports
The TCP and UDP protocols break out each IP address into 65,535 ports,
allowing a computer on a single address to run multiple applications, each
on its own port.
Many applications have standard port assignments; for instance, HTTP uses
port 80; SMTP uses port 25.
Ports till 1024 are reserved for the Operating System, So use a port number
above 1024
mmouf@2017
Establishing a Simple TCP Server
This is 5 Steps Process:
1) Create an object of class TcpListner, which represents a TCP stream
socket through which a server can listen for requests
TcpListner server = new TcpListner(localaddr, port);
Where:
localaddr : is the local address of the Server, object from IPAddress
byte []bt = new byte[]{127,0,0,1};
IPAddress localaddr = new IPAddress(bt);
port : bind the server application to a specific port. Number above 1024
mmouf@2017
Establishing a Simple TCP Server
2) Call TcpListner’s Start method, which makes the TcpListner object
begins to listen for connection request.
The Server creates a connection to the client when it receives a
connection request. This is done by calling TcpListner’s AcceptSocket
method which return object of class Socket that is used to manage a
connection to client
server.Start();
Socket connection = server.AcceptSocket();
3) Establish the stream used for communication with the client.
This is done by creating a NetworkStream object that uses the Socket
object representing the connection to perform the actual sending and
receiving data.
NetworkStream nStream = new NetworkStream(connection);
mmouf@2017
Establishing a Simple TCP Server
4) Process the data between server/client using (ReadByte/WriteByte), or
use BinaryReader and BinaryWriter objects.
BinaryReader br = new BinaryReader(nStream);
5) Terminating connection, this is done when the client and server finish
communication, the server calls method Close of BinaryReader,
BinaryWriter, NetworkStream and Socket to terminate the connection. The
server then returns to step two to wait for the next connection request.
Note: it is recommended to call method Shutdown before method Close to
ensure that all data is sent and received before the Socket closes.
br.Close();
nStream.Close();
connection.Shutdown();
connection.Close();
mmouf@2017
Establishing a Simple TCP Client
This is 4 Steps Process:
1) Create an object of class TcpClient to connect to the server. The
connection is established by calling TcpClient method Connect.
One overloaded version of this method takes two arguments the server's
IP address and its port number as in:
TcpClient client = new TcpClient();
client.Connect( serverAddress, serverPort );
If the connection is successful, TcpClient method Connect returns a
positive integer; otherwise, it returns 0.
NetworkStream nStream = client.GetStream();
BinaryReader br = new BinaryReader(nStream);
mmouf@2017
Establishing a Simple TCP Client
2) The TcpClient uses its GetStream method to get a NetworkStream so that
it can write to and read from the server.
We then use the NetworkStream object to create a BinaryWriter and a
BinaryReader that will be used to send information to and receive
information from the server, respectively.
NetworkStream nStream = client.GetStream();
BinaryReader br = new BinaryReader(nStream);
3) The processing phase, in which the client and the server communicate. In
this phase, the client uses BinaryWriter method Write and BinaryReader
method ReadString to perform the appropriate communications.
mmouf@2017
Establishing a Simple TCP Client
4) After the transmission is complete, the client have to close the connection
by calling method Close on each of BinaryReader, BinaryWriter,
NetworkStream and TcpClient. This closes each of the streams and the
TcpClient's Socket to terminate the connection with the server.
br.Close();
nStream.Close();
mmouf@2017
Threading
mmouf@2017
Introduction
The .NET Framework Class Library provides concurrency primitives.
You specify that applications contain "threads of execution," each of which
designates a portion of a program that may execute concurrently with other
threads this capability is called multithreading.
Multithreading is available to all .NET programming languages, including
C#, Visual Basic and Visual C++.
The .NET Framework Class Library includes multithreading capabilities in
namespace System.Threading.
The basic concept behind threading is to perform multiple operations
concurrently.
Each of these operations can be thought of a separate thread of logic.
Example: The Garbage Collector in .Net
mmouf@2017
Thread Life Cycle
mmouf@2017
Unstarted
Running
Stopped
start
WaitSleepJoin Blocked
Thread Priorities and Thread Scheduling
The Windows operating system supports a concept, called timeslicing, that
enables threads of equal priority to share a processor.
Without timeslicing, each thread in a set of equal-priority threads runs to
completion (unless the thread leaves the Running state and enters the
WaitSleepJoin, Suspended or Blocked state) before the thread's peers get a
chance to execute.
With timeslicing, each thread receives a brief burst of processor time, called
a quantum, during which the thread can execute.
At the completion of the quantum, even if the thread has not finished
executing, the processor is taken away from that thread and given to the next
thread of equal priority, if one is available.
On a single-core computer, the Windows operating system allocate “slices”
of time to each thread (typically 20 ms in Windows)
mmouf@2017
Thread Priorities and Thread Scheduling
The job of the thread scheduler is to keep the highest-priority thread running
at all times and, if there is more than one highest-priority thread, to ensure
that all such threads execute for a quantum in round-robin
Example: assuming a single-processor computer, threads A and B each
execute for a quantum in round-robin fashion until both threads complete
execution.
This means that A gets a quantum of time to run. Then B gets a quantum.
Then A gets another quantum. Then B gets another quantum.
This continues until one thread completes. The processor then devotes all its
power to the thread that remains (unless another thread of that priority is
started).
mmouf@2017
Thread Priorities and Thread Scheduling
A thread's priority can be adjusted with the Priority property, which accepts
values from the ThreadPriority enumeration
(Lowest, BelowNormal, Normal, AboveNormal and Highest. By default,
each thread has priority Normal).
mmouf@2017
Creating and Executing Threads
To create a thread follow the following steps:
1) Create an object from class Thread. This class has only one constructor
takes an object from ThreadStart delegate
2) So, We must define an object from ThreadStart delegate to pass it to the
Thread class constructor
3) Before creating object from the delegate, we must define the function that
will be attached to that delegate and will execute when the Thread object
runs.
This function must : return void and didn’t take any parameter
Note: the Last sequence must be: 3, then 2, then 1
4) Call the Start method of the Thread class to begin execution of the thread.
mmouf@2017
Creating and Executing Threads
class ThreadTest
{
static void Main()
{
Thread t = new Thread (WriteY); // Kick off a new thread
t.Start(); // running WriteY()
// Simultaneously, do something on the main thread.
for (int i = 0; i < 1000; i++) Console.Write ("x");
}
static void WriteY()
{
for (int i = 0; i < 1000; i++) Console.Write ("y");
}
}
mmouf@2017

More Related Content

What's hot

TCP/IP 3-way Handshake
TCP/IP 3-way Handshake TCP/IP 3-way Handshake
TCP/IP 3-way Handshake Alok Tripathi
 
Sample ch10 corr-maurer_netty_december03
Sample ch10 corr-maurer_netty_december03Sample ch10 corr-maurer_netty_december03
Sample ch10 corr-maurer_netty_december03Milena Stefanova
 
Transport layer services
Transport layer servicesTransport layer services
Transport layer servicesMelvin Cabatuan
 
Lec 12(Transport Layer)
Lec 12(Transport Layer)Lec 12(Transport Layer)
Lec 12(Transport Layer)maamir farooq
 
Transport layer udp and tcp network
Transport layer udp and tcp networkTransport layer udp and tcp network
Transport layer udp and tcp networkHamzahMohammed4
 
Features of tcp (part 2) .68
Features of tcp  (part 2) .68Features of tcp  (part 2) .68
Features of tcp (part 2) .68myrajendra
 
TCP - Transmission Control Protocol
TCP - Transmission Control ProtocolTCP - Transmission Control Protocol
TCP - Transmission Control ProtocolPeter R. Egli
 
hajer
hajerhajer
hajerra na
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programmingashok hirpara
 
Tipc Communication Groups
Tipc Communication GroupsTipc Communication Groups
Tipc Communication GroupsJon Maloy
 
Lec 2(intoduction of computer networkes)
Lec 2(intoduction of computer networkes)Lec 2(intoduction of computer networkes)
Lec 2(intoduction of computer networkes)maamir farooq
 
Java API: java.net.InetAddress
Java API: java.net.InetAddressJava API: java.net.InetAddress
Java API: java.net.InetAddressSayak Sarkar
 
Part 4 : reliable transport and sharing resources
Part 4 : reliable transport and sharing resourcesPart 4 : reliable transport and sharing resources
Part 4 : reliable transport and sharing resourcesOlivier Bonaventure
 

What's hot (20)

TCP/IP 3-way Handshake
TCP/IP 3-way Handshake TCP/IP 3-way Handshake
TCP/IP 3-way Handshake
 
Sample ch10 corr-maurer_netty_december03
Sample ch10 corr-maurer_netty_december03Sample ch10 corr-maurer_netty_december03
Sample ch10 corr-maurer_netty_december03
 
CS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMSCS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMS
 
Transport layer services
Transport layer servicesTransport layer services
Transport layer services
 
Networking chapter VI
Networking chapter VINetworking chapter VI
Networking chapter VI
 
Lec 12(Transport Layer)
Lec 12(Transport Layer)Lec 12(Transport Layer)
Lec 12(Transport Layer)
 
Remote method invocation (RMI)
Remote method invocation (RMI)Remote method invocation (RMI)
Remote method invocation (RMI)
 
Transport layer udp and tcp network
Transport layer udp and tcp networkTransport layer udp and tcp network
Transport layer udp and tcp network
 
Part 6 : Internet applications
Part 6 : Internet applicationsPart 6 : Internet applications
Part 6 : Internet applications
 
Data link layer
Data link layerData link layer
Data link layer
 
Features of tcp (part 2) .68
Features of tcp  (part 2) .68Features of tcp  (part 2) .68
Features of tcp (part 2) .68
 
TCP - Transmission Control Protocol
TCP - Transmission Control ProtocolTCP - Transmission Control Protocol
TCP - Transmission Control Protocol
 
Tcp Udp
Tcp UdpTcp Udp
Tcp Udp
 
hajer
hajerhajer
hajer
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programming
 
Tipc Communication Groups
Tipc Communication GroupsTipc Communication Groups
Tipc Communication Groups
 
Lec 2(intoduction of computer networkes)
Lec 2(intoduction of computer networkes)Lec 2(intoduction of computer networkes)
Lec 2(intoduction of computer networkes)
 
Java API: java.net.InetAddress
Java API: java.net.InetAddressJava API: java.net.InetAddress
Java API: java.net.InetAddress
 
Introduction to TCP
Introduction to TCPIntroduction to TCP
Introduction to TCP
 
Part 4 : reliable transport and sharing resources
Part 4 : reliable transport and sharing resourcesPart 4 : reliable transport and sharing resources
Part 4 : reliable transport and sharing resources
 

Viewers also liked

Hojita evangelio domingo v to ciclo a serie
Hojita evangelio domingo v to ciclo a serieHojita evangelio domingo v to ciclo a serie
Hojita evangelio domingo v to ciclo a serieNelson Gómez
 
Mercer Capital's An Introduction to Dividends and Dividend Policy for Private...
Mercer Capital's An Introduction to Dividends and Dividend Policy for Private...Mercer Capital's An Introduction to Dividends and Dividend Policy for Private...
Mercer Capital's An Introduction to Dividends and Dividend Policy for Private...Mercer Capital
 
Hojita evangelio domingo v to ciclo a color
Hojita evangelio domingo v to ciclo a colorHojita evangelio domingo v to ciclo a color
Hojita evangelio domingo v to ciclo a colorNelson Gómez
 
Actividad 1.3 fase 1
Actividad 1.3 fase 1Actividad 1.3 fase 1
Actividad 1.3 fase 1kimberly2731
 
Quảng cáo khuyến mãi
Quảng cáo khuyến mãiQuảng cáo khuyến mãi
Quảng cáo khuyến mãidangcuungoctram
 
Enrollment and Initial Introduction
Enrollment and Initial IntroductionEnrollment and Initial Introduction
Enrollment and Initial IntroductionEmpxtrack Inc.
 
Mi proyecto denisse
Mi proyecto denisseMi proyecto denisse
Mi proyecto denissedenisse0107
 

Viewers also liked (9)

Hojita evangelio domingo v to ciclo a serie
Hojita evangelio domingo v to ciclo a serieHojita evangelio domingo v to ciclo a serie
Hojita evangelio domingo v to ciclo a serie
 
PhilosophyofTeachingStatement01
PhilosophyofTeachingStatement01PhilosophyofTeachingStatement01
PhilosophyofTeachingStatement01
 
Mercer Capital's An Introduction to Dividends and Dividend Policy for Private...
Mercer Capital's An Introduction to Dividends and Dividend Policy for Private...Mercer Capital's An Introduction to Dividends and Dividend Policy for Private...
Mercer Capital's An Introduction to Dividends and Dividend Policy for Private...
 
Hojita evangelio domingo v to ciclo a color
Hojita evangelio domingo v to ciclo a colorHojita evangelio domingo v to ciclo a color
Hojita evangelio domingo v to ciclo a color
 
Actividad 1.3 fase 1
Actividad 1.3 fase 1Actividad 1.3 fase 1
Actividad 1.3 fase 1
 
Quảng cáo khuyến mãi
Quảng cáo khuyến mãiQuảng cáo khuyến mãi
Quảng cáo khuyến mãi
 
Enrollment and Initial Introduction
Enrollment and Initial IntroductionEnrollment and Initial Introduction
Enrollment and Initial Introduction
 
secondary market ppt.
secondary market ppt.secondary market ppt.
secondary market ppt.
 
Mi proyecto denisse
Mi proyecto denisseMi proyecto denisse
Mi proyecto denisse
 

Similar to Intake 37 12

Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project ReportKavita Sharma
 
Network protocols
Network protocolsNetwork protocols
Network protocolsAbiud Orina
 
Cs556 section3
Cs556 section3Cs556 section3
Cs556 section3farshad33
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26Max Kleiner
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theoryMukesh Tekwani
 
Lec 6(Application Layer)
Lec 6(Application Layer)Lec 6(Application Layer)
Lec 6(Application Layer)maamir farooq
 
692015 programming assignment 1 building a multi­threaded w
692015 programming assignment 1 building a multi­threaded w692015 programming assignment 1 building a multi­threaded w
692015 programming assignment 1 building a multi­threaded wsmile790243
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket ProgrammingMousmi Pawar
 
Chapter 2B-Communication.ppt
Chapter 2B-Communication.pptChapter 2B-Communication.ppt
Chapter 2B-Communication.pptsirajmohammed35
 
2.communcation in distributed system
2.communcation in distributed system2.communcation in distributed system
2.communcation in distributed systemGd Goenka University
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik TambekarPratik Tambekar
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptxEliasPetros
 

Similar to Intake 37 12 (20)

Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project Report
 
Network protocols
Network protocolsNetwork protocols
Network protocols
 
NP-lab-manual (1).pdf
NP-lab-manual (1).pdfNP-lab-manual (1).pdf
NP-lab-manual (1).pdf
 
NP-lab-manual.pdf
NP-lab-manual.pdfNP-lab-manual.pdf
NP-lab-manual.pdf
 
NP-lab-manual.docx
NP-lab-manual.docxNP-lab-manual.docx
NP-lab-manual.docx
 
Cs556 section3
Cs556 section3Cs556 section3
Cs556 section3
 
Cs556 section3
Cs556 section3Cs556 section3
Cs556 section3
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theory
 
Week9 lec1
Week9 lec1Week9 lec1
Week9 lec1
 
Lec 6(Application Layer)
Lec 6(Application Layer)Lec 6(Application Layer)
Lec 6(Application Layer)
 
692015 programming assignment 1 building a multi­threaded w
692015 programming assignment 1 building a multi­threaded w692015 programming assignment 1 building a multi­threaded w
692015 programming assignment 1 building a multi­threaded w
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket Programming
 
Chapter 2B-Communication.ppt
Chapter 2B-Communication.pptChapter 2B-Communication.ppt
Chapter 2B-Communication.ppt
 
2.communcation in distributed system
2.communcation in distributed system2.communcation in distributed system
2.communcation in distributed system
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik Tambekar
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
 

More from Mahmoud Ouf

More from Mahmoud Ouf (20)

Relation between classes in arabic
Relation between classes in arabicRelation between classes in arabic
Relation between classes in arabic
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
Intake 38 data access 4
Intake 38 data access 4Intake 38 data access 4
Intake 38 data access 4
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
 
Intake 38 data access 1
Intake 38 data access 1Intake 38 data access 1
Intake 38 data access 1
 
Intake 38 12
Intake 38 12Intake 38 12
Intake 38 12
 
Intake 38 10
Intake 38 10Intake 38 10
Intake 38 10
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Intake 38 8
Intake 38 8Intake 38 8
Intake 38 8
 
Intake 38 7
Intake 38 7Intake 38 7
Intake 38 7
 
Intake 38 6
Intake 38 6Intake 38 6
Intake 38 6
 
Intake 38 5 1
Intake 38 5 1Intake 38 5 1
Intake 38 5 1
 
Intake 38 5
Intake 38 5Intake 38 5
Intake 38 5
 
Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
 
Intake 38 3
Intake 38 3Intake 38 3
Intake 38 3
 
Intake 38 2
Intake 38 2Intake 38 2
Intake 38 2
 
Intake 38_1
Intake 38_1Intake 38_1
Intake 38_1
 
Intake 37 DM
Intake 37 DMIntake 37 DM
Intake 37 DM
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
Intake 37 ef1
Intake 37 ef1Intake 37 ef1
Intake 37 ef1
 

Recently uploaded

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 

Intake 37 12

  • 1. Visual C# .Net using framework 4.5 Eng. Mahmoud Ouf Lecture 12 mmouf@2017
  • 3. Type of Communications There are two types of communications: • Connection oriented communications Which are similar to the telephone system, in which a connection is established and held for the length of the session • Connectionless communications Which are similar to the postal service, in which two letters mailed from the same place and to the same destination may actually take two different paths through the system and even arrive at different times mmouf@2017
  • 4. Communication Protocols There are two types of protocols: • Transmission Control Protocol (TCP) connection-oriented communication protocol which guarantees that sent packets will arrive at the intended receiver undamaged and in the correct sequence. If packets of information don't arrive at the recipient, TCP ensures that the packets are sent again. If the packets arrive out of order, TCP reassembles them in the correct order transparently to the receiving application. If duplicate packets arrive, TCP discards them. mmouf@2017
  • 5. Communication Protocols • User Datagram Protocol (UDP) connectionless communication protocol. It incurs the minimum overhead necessary to communicate between applications. UDP makes no guarantees that packets, called datagrams, will reach their destination or arrive in their original order. mmouf@2017
  • 7. Addresses and Ports To communication with computer or device, computer requires an address. The Internet uses two addressing systems: IPv4 (Currently the dominant addressing system) IPv4 addresses are 32 bits wide. When string-formatted, IPv4 addresses are written as four dot-separated decimals (e.g., 101.102.103.104). An address can be unique in the world or unique within a particular subnet (such as on a corporate network). IPv6 (The newer 128-bit addressing system) Addresses are string-formatted in hexadecimal with a colon separator (e.g., [3EA0:FFFF:198A:E4A3:4FF2:54fA:41BC:8D31]). mmouf@2017
  • 8. Addresses and Ports The TCP and UDP protocols break out each IP address into 65,535 ports, allowing a computer on a single address to run multiple applications, each on its own port. Many applications have standard port assignments; for instance, HTTP uses port 80; SMTP uses port 25. Ports till 1024 are reserved for the Operating System, So use a port number above 1024 mmouf@2017
  • 9. Establishing a Simple TCP Server This is 5 Steps Process: 1) Create an object of class TcpListner, which represents a TCP stream socket through which a server can listen for requests TcpListner server = new TcpListner(localaddr, port); Where: localaddr : is the local address of the Server, object from IPAddress byte []bt = new byte[]{127,0,0,1}; IPAddress localaddr = new IPAddress(bt); port : bind the server application to a specific port. Number above 1024 mmouf@2017
  • 10. Establishing a Simple TCP Server 2) Call TcpListner’s Start method, which makes the TcpListner object begins to listen for connection request. The Server creates a connection to the client when it receives a connection request. This is done by calling TcpListner’s AcceptSocket method which return object of class Socket that is used to manage a connection to client server.Start(); Socket connection = server.AcceptSocket(); 3) Establish the stream used for communication with the client. This is done by creating a NetworkStream object that uses the Socket object representing the connection to perform the actual sending and receiving data. NetworkStream nStream = new NetworkStream(connection); mmouf@2017
  • 11. Establishing a Simple TCP Server 4) Process the data between server/client using (ReadByte/WriteByte), or use BinaryReader and BinaryWriter objects. BinaryReader br = new BinaryReader(nStream); 5) Terminating connection, this is done when the client and server finish communication, the server calls method Close of BinaryReader, BinaryWriter, NetworkStream and Socket to terminate the connection. The server then returns to step two to wait for the next connection request. Note: it is recommended to call method Shutdown before method Close to ensure that all data is sent and received before the Socket closes. br.Close(); nStream.Close(); connection.Shutdown(); connection.Close(); mmouf@2017
  • 12. Establishing a Simple TCP Client This is 4 Steps Process: 1) Create an object of class TcpClient to connect to the server. The connection is established by calling TcpClient method Connect. One overloaded version of this method takes two arguments the server's IP address and its port number as in: TcpClient client = new TcpClient(); client.Connect( serverAddress, serverPort ); If the connection is successful, TcpClient method Connect returns a positive integer; otherwise, it returns 0. NetworkStream nStream = client.GetStream(); BinaryReader br = new BinaryReader(nStream); mmouf@2017
  • 13. Establishing a Simple TCP Client 2) The TcpClient uses its GetStream method to get a NetworkStream so that it can write to and read from the server. We then use the NetworkStream object to create a BinaryWriter and a BinaryReader that will be used to send information to and receive information from the server, respectively. NetworkStream nStream = client.GetStream(); BinaryReader br = new BinaryReader(nStream); 3) The processing phase, in which the client and the server communicate. In this phase, the client uses BinaryWriter method Write and BinaryReader method ReadString to perform the appropriate communications. mmouf@2017
  • 14. Establishing a Simple TCP Client 4) After the transmission is complete, the client have to close the connection by calling method Close on each of BinaryReader, BinaryWriter, NetworkStream and TcpClient. This closes each of the streams and the TcpClient's Socket to terminate the connection with the server. br.Close(); nStream.Close(); mmouf@2017
  • 16. Introduction The .NET Framework Class Library provides concurrency primitives. You specify that applications contain "threads of execution," each of which designates a portion of a program that may execute concurrently with other threads this capability is called multithreading. Multithreading is available to all .NET programming languages, including C#, Visual Basic and Visual C++. The .NET Framework Class Library includes multithreading capabilities in namespace System.Threading. The basic concept behind threading is to perform multiple operations concurrently. Each of these operations can be thought of a separate thread of logic. Example: The Garbage Collector in .Net mmouf@2017
  • 18. Thread Priorities and Thread Scheduling The Windows operating system supports a concept, called timeslicing, that enables threads of equal priority to share a processor. Without timeslicing, each thread in a set of equal-priority threads runs to completion (unless the thread leaves the Running state and enters the WaitSleepJoin, Suspended or Blocked state) before the thread's peers get a chance to execute. With timeslicing, each thread receives a brief burst of processor time, called a quantum, during which the thread can execute. At the completion of the quantum, even if the thread has not finished executing, the processor is taken away from that thread and given to the next thread of equal priority, if one is available. On a single-core computer, the Windows operating system allocate “slices” of time to each thread (typically 20 ms in Windows) mmouf@2017
  • 19. Thread Priorities and Thread Scheduling The job of the thread scheduler is to keep the highest-priority thread running at all times and, if there is more than one highest-priority thread, to ensure that all such threads execute for a quantum in round-robin Example: assuming a single-processor computer, threads A and B each execute for a quantum in round-robin fashion until both threads complete execution. This means that A gets a quantum of time to run. Then B gets a quantum. Then A gets another quantum. Then B gets another quantum. This continues until one thread completes. The processor then devotes all its power to the thread that remains (unless another thread of that priority is started). mmouf@2017
  • 20. Thread Priorities and Thread Scheduling A thread's priority can be adjusted with the Priority property, which accepts values from the ThreadPriority enumeration (Lowest, BelowNormal, Normal, AboveNormal and Highest. By default, each thread has priority Normal). mmouf@2017
  • 21. Creating and Executing Threads To create a thread follow the following steps: 1) Create an object from class Thread. This class has only one constructor takes an object from ThreadStart delegate 2) So, We must define an object from ThreadStart delegate to pass it to the Thread class constructor 3) Before creating object from the delegate, we must define the function that will be attached to that delegate and will execute when the Thread object runs. This function must : return void and didn’t take any parameter Note: the Last sequence must be: 3, then 2, then 1 4) Call the Start method of the Thread class to begin execution of the thread. mmouf@2017
  • 22. Creating and Executing Threads class ThreadTest { static void Main() { Thread t = new Thread (WriteY); // Kick off a new thread t.Start(); // running WriteY() // Simultaneously, do something on the main thread. for (int i = 0; i < 1000; i++) Console.Write ("x"); } static void WriteY() { for (int i = 0; i < 1000; i++) Console.Write ("y"); } } mmouf@2017