IP-based communication
programming involves two basic categories of communications,
connectionless and connection-oriented. The types of solutions
we are discussing here use a connection oriented SOCK_STREAM
type socket over TCP versus a connectionless SOCK_DGRAM type
socket over UDP.
Our socket communication will follow the following
steps.
1) Create a socket
2) Bind the socket to an address or end point
3) Listen for an incoming communications attempt
4) Accept the communication
5) Send and receive messages buffers
6) Shutdown the communication channel
7) Close the socket connection
You will need to add the statement “using
System.Net;” to the top of your classes to try out the
techniques listed here. This is the namespace containing most
the classes you are going to need to create our sockets and
manage the communications.
Each of the parties in a socket communication
is called and end point. When you create your endpoint you need
to decide which address family you are using. This specifies
which addressing scheme that a socket will use to resolve an
address. The one you will most likely use is "InterNetwork"
which indicates that you are using IP version 4 such as what
is used on most Ethernet networks and the Internet (e.g. 10.0.0.1).
.NET and the .NET compact framework support a lot of addressing
schemes out of the box. Some of the more useful and interesting
ones include AppleTalk, ATM, Banyan, Data Link, ECMA, InterNetworkV6,
NetBIOS, OSI and SNA. You can also specify "Unknown"
and "Unspecified." This article addresses only “InterNetwork”
addressing but the concepts detailed here transfer to the other
address family types.
Each endpoint has a unique address which is
a combination of an IP address and a port number. You will need
the local IP addresses of your devices for communication to
occur. There is an IPAddress class which you can instantiate
it by passing the value of your IP address as a byte array or
a long. If you need to pass in a string as your values then
there is a parse method which is shown below.
NEXT>>
|