Network Programming PDF
Network Programming PDF
Network Programming PDF
Basic Outline
An Overview of Sockets
Working with Sockets in .NET
Asynchronous Programming
Socket Permissions
Basic Outline
An Overview of Sockets
Working with Sockets in .NET
Asynchronous Programming
Socket Permissions
An Overview of Sockets
Definition
A socket is one end of a two-way communication link between two
programs running on a network
Connection can be local or remote
Socket implementation provides the encapsulation of the network and
transport level protocols
A socket, being a resource, is also represented by a descriptor
Socket Types
Stream Sockets
Connection-orientated
Consists of a stream of bytes that can be bidirectional
Guarantees error correction, handles delivery and preserves data
sequence and guarantees non-duplicated data
High level of quality using TCP
Suitable for large amounts of data
Large overhead makes it bulky for small amounts of data
Path is formed before communication starts (ensures that both
parties are active and participating)
Uses data packets and relies on TCP for delivery of packets
Datagram Sockets
Raw Sockets
Sockets and Ports
An Overview of Sockets
Definition
Socket Types
Stream Sockets
Datagram Sockets
Also called connectionless sockets (no explicit connections
are established)
Message is just sent without knowledge of the receiver
Uses UDP to pass data from client to server
Message size limitations and no guarantee of delivery
Used when overhead of stream sockets does not warrant the
message (i.e. when the message is too small/insignificant)
Raw Sockets
An Overview of Sockets
Definition
Socket Types
Stream Sockets
Datagram Sockets
Raw Sockets
A socket that takes packets, bypassing the TCP and UDP
layers in the TCP/IP stack and sends them directly to the
application
Purpose is to bypass the mechanism by which the computer
handles TCP/IP.
Provides a custom implementation of the TCP/IP stack
It is more efficient than going through the clients main stack
No processing on the packet (i.e. raw)
The receiving application has to handle the data
appropriately and deal with actions such as stripping off
headers and parsing
Used for custom low-level protocol applications
Sockets and Ports
An Overview of Sockets
Definition
Socket Types
Stream Sockets
Datagram Sockets
Raw Sockets
Sockets and Ports
A port is defined to solve the problem of communicating with
multiple applications simultaneously; it basically expands the
notion of an IP address
A computer can identify an arriving packet by the port number it
is arriving through
Port numbers are established when connections are made
The socket is composed of the IP address of the machine and
the port number used by the TCP application; this is also called
an endpoint.
Endpoints are unique across the entire Internet because IP
addresses are unique
Certain services have port numbers reserved for them; these are
the well-known port numbers (FTP = 21)
An Overview of Sockets
Port
Server
Connection Request
Client
Basic Outline
An Overview of Sockets
Working with Sockets in .NET
Asynchronous Programming
Socket Permissions
Description
MulticastOption
Contains IPAddress values used to join and drop multicast groups. Sets IP
address values for joining or leaving an IP multicast group.
NetworkStream
TcpClient
Provides client connections for TCP network services. Builds on the socket class to
provide TCP services at a higher level. TCPClient provides several methods for
sending and receiving data over a network.
TcpListener
Listens for connections from TCP network clients. Builds on the low-level Socket
class. Its main purpose is in server applications. This class listens for the incoming
client connections and notifies the application of any connections.
UdpClient
SocketException
The exception that is thrown when a socket error occurs. The exception thrown when
an error occurs in a socket.
Socket
System.Net.Sockets.Socket
Properties
AddressFamily
Gets the address family of the Socket. The value is from the
Socket.AddressFamily enumeration.
Available
Gets the amount of data that has been received from the network and is
available to be read (returns the amount of available data to read).
Blocking
Gets or sets a value that indicates whether the Socket is in blocking mode.
Connected
LocalEndPoint
System.Net.Sockets.Socket
Properties
ProtocolType
RemoteEndPoint
SocketType
SupportsIPv4
SupportsIPv6
System.Net.Sockets.Socket
Methods
Method
Description
Accept
Creates a new Socket for a newly created connection to handle the incoming
connection request.
Bind
Close
Connect
GetSocketOption
IOControl
Overloaded. Sets low-level operating modes for the Socket. This method
provides low-level access to the underlying socket instance of the Socket
class.
System.Net.Sockets.Socket
Methods
Method
Description
Listen
Receive
Poll
Select
Send
SetSocketOption
Shutdown
Building
a TCbased
Server
Serve
r
Open a Socket
(Socket)
using
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Net.Sockets;
Note: System.Net & System.Net.Sockets
System.Net;
namespace TestSockets
{
class SocketServer
Returns all network
{
addresses supported
static void Main(string[] args)
{
//establish the local endpoint for the socket
IPHostEntry ipHost = Dns.GetHostEntry("localhost");
IPAddress ipAddr = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 1100);
bytesRec);
if (data.IndexOf("<TheEnd>") > -1)
break;
}//end of while
Accept may open up multiple sockets. Once the client and server are connected
with each other, you an send and receive using the Send and Receive methods of
the Socket class. The exact protocol definition between the client and server
needs to be clearly defined before sockets may send and receive.
Client
Building
a TCbased
Client
Open a Socket
(Socket)
Send/Receive Data
(Send/Receive)
Close Socket
(Close)
using
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Net.Sockets;
System.Net;
namespace TestSocketClient
{
class SocketClient
{
static void Main(string[] args)
{
//Data buffer for incoming data
byte[] bytes = new byte[1024];
//Connect to a remote device
try
{
//Establish the remote endpoint for the socket
IPHostEntry ipHost = Dns.GetHostEntry("127.0.0.1");
IPAddress ipAddr = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 1100);
Socket sender = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
//Connect the socket to the remote endpoint
sender.Connect(ipEndPoint);
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Net;
namespace PortScanner
{
class Program
{
static void Main(string[] args)
{
IPAddress address = IPAddress.Parse("127.0.0.1");
int[] listeningPorts = new int[50];
int count = -1;
Socket sSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
//Loop through ports 1 to 1024
for (int i = 1; i <= 1024; i++)
{
Console.WriteLine("Checking port {0}", i.ToString());
try
{
//Establish the remote endpoint for the socket
IPEndPoint endPoint = new IPEndPoint(address, i);
sSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
Description
AccessDenied
AddressAlreadyInUse
AddressFamilyNotSupporte
AddressNotAvailable
AlreadyInProgress
ConnectionAborted
ConnectionRefused
ConnectionReset
DestinationAddressRequired
Disconnecting
Fault
HostDown
HostNotFound
No such host is known. The name is not an official host name or alias.
Description
HostUnreachable
InProgress
Interrupted
InvalidArgument
IOPending
IsConnected
MessageSize
NetworkDown
NetworkReset
The application tried to set KeepAlive on a connection that has already timed out.
NetworkUnreachable
NoBufferSpaceAvailable
NoData
The requested name or IP address was not found on the name server.
NoRecovery
Description
NotConnected
The application tried to send or receive data, and the Socket is not connected.
NotInitialized
NotSocket
OperationAborted
The overlapped operation was aborted due to the closure of the Socket.
OperationNotSupported
ProcessLimit
ProtocolFamilyNotSupported
ProtocolNotSupported
ProtocolOption
ProtocolType
Shutdown
A request to send or receive data was disallowed because the Socket has already
been closed.
SocketError
Description
SocketNotSupported
The support for the specified socket type does not exist in this address family.
Success
SystemNotReady
TimedOut
The connection attempt timed out, or the connected host has failed to respond.
TooManyOpenSockets
There are too many open sockets in the underlying socket provider.
TryAgain
The name of the host could not be resolved. Try again later.
TypeNotFound
VersionNotSupported
WouldBlock
GetSocketOption
SetSocketOption
Name
Description
Socket.SetSocketOption
(SocketOptionLevel, SocketOptionName,
Boolean)
Socket.SetSocketOption
(SocketOptionLevel, SocketOptionName,
Byte[])
Socket.SetSocketOption
(SocketOptionLevel, SocketOptionName,
Int32)
Socket.SetSocketOption
(SocketOptionLevel, SocketOptionName,
Object)
SocketOptionLevel
Member name
Description
IP
IPv6
Socket
Tcp
Udp
SocketOptionName
Member name
Description
AcceptConnection
AddMembership
AddSourceMembership
BlockSource
Broadcast
BsdUrgent
Use urgent data as defined in RFC-1222. This option can be set only
once; after it is set, it cannot be turned off.
ChecksumCoverage
Debug
DontFragment
DontLinger
DontRoute
DropMembership
DropSourceMembership
Error
SocketOptionName
Member name
Description
ExclusiveAddressUse
Expedited
Use expedited data as defined in RFC-1222. This option can be set only
once; after it is set, it cannot be turned off.
HeaderIncluded
HopLimit
IPOptions
IpTimeToLive
KeepAlive
Use keep-alives.
Linger
MaxConnections
MulticastInterface
SocketOptionName
Member name
Description
MulticastLoopback
An IP multicast loopback.
MulticastTimeToLive
NoChecksum
NoDelay
OutOfBandInline
PacketInformation
ReceiveBuffer
Specifies the total per-socket buffer space reserved for receives. This is
unrelated to the maximum message size or the size of a TCP window.
ReceiveLowWater
ReceiveTimeout
SocketOptionName
Member name
Description
ReuseAddress
SendBuffer
Specifies the total per-socket buffer space reserved for sends. This is
unrelated to the maximum message size or the size of a TCP window.
SendLowWater
SendTimeout
Type
TypeOfService
UnblockSource
UpdateAcceptContext
UpdateConnectContext
UseLoopback
ReuseAddress
By default only one socket may be bound
to a local address that is already in use.
However, you may want to bind more than
one socket to a local address
The solution is the ReuseAddress
using
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Net;
System.Net.Sockets;
ReuseAddress
(throws
error)
namespace SocketReuseAddress
{
class Program
{
static void Main(string[] args)
{
try
{
//Establish the local endpoint for the socket
IPEndPoint ipEndPoint = new IPEndPoint(Dns.GetHostEntry(Dns.GetHostName()).AddressList[0], 11000);
//Create a TCP/IP Socket
Socket sListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//Bind the socket to the local endpoint and listen to incoming sockets
sListener.Bind(ipEndPoint);
sListener.Listen(10);
//Create a new socket
Socket sListener2 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//Bind the socket to the local endpoint and listen to the incoming sockets
sListener2.Bind(ipEndPoint);
sListener2.Listen(10);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
//Stop console from closing
Console.ReadLine();
}
}
}
using
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Net;
System.Net.Sockets;
ReuseAddress
(fixed)
namespace SocketReuseAddress
{
class Program
{
static void Main(string[] args)
{
try
{
//Establish the local endpoint for the socket
IPEndPoint ipEndPoint = new IPEndPoint(Dns.GetHostEntry(Dns.GetHostName()).AddressList[0], 11000);
//Create a TCP/IP Socket
Socket sListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//Bind the socket to the local endpoint and listen to incoming sockets
sListener.Bind(ipEndPoint);
sListener.Listen(10);
//Create a new socket
Socket sListener2 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//Adding ReuseAddress option to prevent error message
sListener2.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
//Bind the socket to the local endpoint and listen to the incoming sockets
sListener2.Bind(ipEndPoint);
sListener2.Listen(10);
Console.WriteLine("Sockets successfully bound.");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
//Stop console from closing
Console.ReadLine();
}
}
Linger
Linger (from dictionary.com)
v. lingered, lingering, lingers
v. intr.
To be slow in leaving, especially out of reluctance; tarry. See
Synonyms at stay1.
To remain feebly alive for some time before dying.
To persist: an aftertaste that lingers.
To proceed slowly; saunter.
To be tardy in acting; procrastinate.
v. tr.
To pass (a period of time) in a leisurely or aimless manner.
Linger
// Send operations will time-out if
//confirmation is not received within 1000
//milliseconds.
s.SetSocketOption (SocketOptionLevel.Socket,
SocketOptionName.SendTimeout, 1000);
// The socket will linger for 10 seconds
//after Socket.Close is called.
LingerOption lingerOption = new LingerOption
(true, 10);
s.SetSocketOption (SocketOptionLevel.Socket,
SocketOptionName.Linger, lingerOption);
Basic Outline
An Overview of Sockets
Working with Sockets in .NET
Asynchronous Programming
Socket Permissions
Asynchronous Programming
Introduction
Creating an Asynchronous Client
Application
Creating an Asynchronous Server
Application
Asynchronous Programming
Most socket functions
Indefinite time to complete
Blocked
Asynchronous programming
Functions that cant afford to hang around
A connection does not block an application
Events can be..
Signalled
Non-signalled
Asynchronous Programming
Two event types
Automatic (set themselves back to non-signalled state
when they are signalled)
Manual (stay signalled until manually reset to nonsignalled state)
Asynchronous Programming
Introduction
Creating an Asynchronous Client
Application
Creating an Asynchronous Server
Application
Secondary Thread
Create Socket
Initialise Connection Request: BeginConnect
Waiting
ConnectCallBack()
Initialise Sending Request: BeginSend
Waiting
SendCallBack()
Initialise Receiving Request: BeginReceive
Asynchronous Client
using
using
using
using
using
System;
System.Net;
System.Net.Sockets;
System.Text;
System.Threading;
namespace AsyncClientExample
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class AsyncClient
{
public static ManualResetEvent connectDone = new ManualResetEvent( false );
public static ManualResetEvent sendDone = new ManualResetEvent( false );
public static ManualResetEvent receiveDone = new ManualResetEvent( false );
public static string response = string.Empty;
public static string sb = string.Empty;
public static byte[] buffer = new byte[8192];
Asynchronous Client
//ConnectCallback is called when connection is ready
public static void ConnectCallback( IAsyncResult a )
{
Thread thr = Thread.CurrentThread;
Console.WriteLine( "ConnectCallback Thread State: " + thr.ThreadState );
Socket sktClient = (Socket) a.AsyncState;
sktClient.EndConnect( a );
Console.WriteLine("Socket connected to {0}", sktClient.RemoteEndPoint.ToString()
);
//Signal connectDone event to inform other thread
//that connection is ready for use
connectDone.Set();
} //End public static void ConnectCallback( IAsyncResult a )
Asynchronous Client
//SendCallback is called when sending is complete
public static void SendCallback( IAsyncResult a )
{
Thread thr = Thread.CurrentThread;
Console.WriteLine( "SendCallback Thread State: " +
thr.ThreadState );
Socket sktClient = (Socket) a.AsyncState;
int bytesSent = sktClient.EndSend( a );
Console.WriteLine( "Sent {0} bytes to server", bytesSent
);
//Signal sentDone event
sendDone.Set();
} //End public static void SendCallback( IAsyncResult a )
Asynchronous Client
//ReceiveCallback is called when receiving is complete
public static void ReceiveCallback( IAsyncResult a )
{
Thread thr = Thread.CurrentThread;
Console.WriteLine( "ReceiveCallback Thread State: " + thr.ThreadState );
Socket sktClient = (Socket) a.AsyncState;
int bytesRead = sktClient.EndReceive( a );
if( bytesRead > 0 )
{
sb += Encoding.ASCII.GetString(buffer,0, bytesRead);
sktClient.BeginReceive( buffer, 0, buffer.Length, 0,
new AsyncCallback( ReceiveCallback), sktClient );
}
else
{
//Signal receiveDone event
receiveDone.Set();
}
} //End public static void receiveCallback( IAsyncResult a )
Asynchronous Client
[STAThread]
static void Main(string[] args)
{
try
{
Thread thr = Thread.CurrentThread;
Console.WriteLine( "Main Thread State: " +
thr.ThreadState );
IPHostEntry ipHost = Dns.Resolve( "127.0.0.1" );
IPAddress ipAddr = ipHost.AddressList[0];
IPEndPoint endPoint = new IPEndPoint( ipAddr, 11000
);
Socket sktClient = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,ProtocolType.Tcp );
Asynchronous Client
//Create new thread to initiate the connection to //the server
sktClient.BeginConnect( endPoint, new AsyncCallback(
ConnectCallback ), sktClient );
connectDone.WaitOne();
string data = "This is a test";
for( int i = 0; i < 72; i++ )
{
data += i.ToString() + ":" + (new string( '=', i ));
}
byte[] byteData = Encoding.ASCII.GetBytes( data + "." );
//Send data in a separate thread
sktClient.BeginSend( byteData, 0, byteData.Length,
SocketFlags.None, new AsyncCallback( SendCallback ), sktClient
);
Asynchronous Client
//Do something in the main thread
byte[] byteData = Encoding.ASCII.GetBytes( data + "." );
//Send data in a separate thread
sktClient.BeginSend( byteData, 0, byteData.Length,
SocketFlags.None,
new AsyncCallback( SendCallback ), sktClient );
//Do something in the main thread
for( int i = 0; i < 10; i++ )
{
Console.WriteLine( i );
Thread.Sleep( 10 );
}
//Wait until all sending is done
sendDone.WaitOne();
Asynchronous Client
//Start receiving data in a separate thread
sktClient.BeginReceive( buffer, 0, buffer.Length, SocketFlags.None,
new AsyncCallback( ReceiveCallback ), sktClient );
receiveDone.WaitOne();
Console.WriteLine( "Response received: {0} ", sb );
sktClient.Shutdown( SocketShutdown.Both );
sktClient.Close();
}
catch( Exception e )
{
Console.WriteLine( e.ToString() );
}
Console.ReadLine();
} //End Main
} //End Class
} //End Namespace
Asynchronous Programming
Introduction
Creating an Asynchronous Client
Application
Creating an Asynchronous Server
Application
Asynchronous Server
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace AsyncServerExample
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class AsyncServer
{
//Buffer to send and receive data
public static byte[] buffer = new byte[8192];
//Event class to support synchronization
public static ManualResetEvent socketEvent = new ManualResetEvent( false );
[STAThread]
static void Main(string[] args)
{
Console.WriteLine( "Main Thread ID: " +
AppDomain.GetCurrentThreadId() );
byte[] bytes = new byte[8192];
IPHostEntry ipHost = Dns.Resolve( Dns.GetHostName() );
IPAddress ipAddr = ipHost.AddressList[0];
IPEndPoint localEnd = new IPEndPoint( ipAddr, 11000 );
Socket sListener = new Socket( AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp );
//Bind socket
sListener.Bind( localEnd);
//Start listening
sListener.Listen( 10 );
Console.WriteLine( "Waiting for a connection....." );
AsyncCallback aCallback = new AsyncCallback(
AcceptCallback );
//Asynchronous method for accepting connections
sListener.BeginAccept( aCallback, sListener );
//Waiting for other threads to finish
socketEvent.WaitOne();
Console.Read();
} //End Main()
Method AcceptCallBack
public static void AcceptCallback( IAsyncResult ar )
{
Console.WriteLine( "AcceptCallback Thread ID: " +
AppDomain.GetCurrentThreadId() );
//Retrieved the socket
Socket listener = (Socket) ar.AsyncState;
//New socket
Socket handler = listener.EndAccept( ar );
handler.BeginReceive( buffer, 0, buffer.Length, 0,
new AsyncCallback( ReceivCallback), handler );
} //End public static void AcceptCallback(
IAsyncResult ar )
Basic Outline
An Overview of Sockets
Working with Sockets in .NET
Asynchronous Programming
Socket Permissions
Socket Permissions
Introduction
Using Imperative Security
Using Declarative Security
Socket Permissions
Help develop secure code
Only the code that has permission to run in the current context can
be executed
Each code-access permission demonstrates one of the following
rights:
The right to access protected resources such as files
The right to perform a protected operation such as accessing managed
code
SocketPermission class
enforces code-access permissions
Used to control rights to make or accept connections (control
connections via sockets)
Consists of host specification and a set of actions specifying ways to
connect to the host
Enforces secure code by monitoring the values of the host name, IP
address and transport protocol
Socket Permissions
There are two ways to enforce security
permission in C# sockets:
Imperatively
Implements permissions by creating a new instance of the
SocketPermission class to demand a particular
permission when the code is executed, such as the right to
make a TCP connection. It is generally used when the
security setting are changed at runtime.
Declaratively
Declarative syntax uses attributes to place security
information into the metadata of your code, so that the client
calls your code can use reflection to see what permissions
are required by the code.
Imperative Security
Creates a new instance of the SocketPermission
class to enforce security
Use imperative security syntax to perform demands and
overrides, but not requests
Before calling the corresponding security measure, it is
necessary to initialise the state of the
SocketPermission class through the constructor so
that it represents the particular form of permission that
you want to use.
This kind of security is only useful when you have some
information needed for security that is available only at
runtime; for example; if you want to secure some host
over a port but dont know the host name and port
number until the program executes
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Net;
System.Net.Sockets;
System.Security;
System.Security.Permissions;
Imperative
Security
namespace SocketsImperativeSecurity
{
class Program
{
static void Main(string[] args)
{
//Option could be either Assert or Deny passed on the command line
//If option is Assert, then the program executes successfully
//Otherwise, it triggers a SecurityException
string option = null;
if (args.Length > 0)
{
option = args[0];
}
else
{
option = "assert";
} //end of if-else
Console.WriteLine("option: " + option);
MethodA(option);
Console.WriteLine("Done");
}
Declarative Security
Uses .NET attributes to place security
information inside the metadata of the code
Attributes can be placed at the assembly, class
or member level to indicate the type of request,
demand, or override that is needed.
In order to use this security syntax, the state of
the data must be initialised first for the
SocketPermissionAttribute object through
the declarative syntax, so that it represents the
form of permission that is being enforced on the
code.
Declarative Security
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Net;
System.Net.Sockets;
System.Security;
System.Security.Permissions;
namespace SocketDeclarativeSecurity
{
class Program
{
static void Main(string[] args)
{
LegalMethod();
IllegalMethod();
Console.Write("Press a key to continue.");
Console.ReadLine();
}
[SocketPermission (SecurityAction.Assert, Access = "Connect", Host = "127.0.0.1", Port = "All", Transport = "Tcp")]
public static void LegalMethod()
{
Console.WriteLine("Legal Method");
IPHostEntry ipHost = Dns.GetHostEntry("127.0.0.1");
IPAddress ipAddr = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11000);
Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
//Connect the socket to the remote endpoint. Catch any errors
sender.Connect(ipEndPoint);
Console.WriteLine("Socket connected to {0}", sender.RemoteEndPoint.ToString());
} //end of try
catch (SecurityException se)
{
Console.WriteLine("Security Exception: " + se);
} //end of catch
catch (SocketException se)
{
Console.WriteLine("Socket Exception: " + se);
} //end of catch
finally
{
if (sender.Connected)
{
//release the socket
sender.Shutdown(SocketShutdown.Both);
sender.Close();
}
} //end of finally
} // end of legalMethod
Legal Method
Illegal
Method
}
}
Summary
Socket class
Two main socket types
Stream sockets
Datagram sockets
System.Net.Sockets namespace
SocketException Class
Finally block should contain Close and Shutdown methods
Declarative
Permissions needed are known at compile-time