Thursday, May 21, 2009

Exercise 5: Answer

1. Using any familiar programming language environment, what do you know about sockets (network) programming? Coming from a .net framework / Microsoft programming paradigm, the use of the term socket is completely new to me. So my immediate answer to the question is not a thing. However if we review the definition given by (Ince, p50)
"Each communication channel into and out of a TCP/IP-based computer is identified by the unique pair of numbers consisting of the IP address and the port number. This combination is a programming abstraction known as a socket."
This gives me a line of enquiry to take, and so reviewing remoting in a .net environment leads us to (as an example) looking at registering a communication channel and specifying the port. This can be done with the System.Runtime.Remoting.Channels.Http class. Looking at (MSDN)
Sockets The System.Net.Sockets namespace contains a managed implementation of the Windows Sockets interface. All other network-access classes in the System.Net namespace are built on top of this implementation of sockets. The .NET Framework Socket class is a managed-code version of the socket services provided by the Winsock32 API. In most cases, the Socket class methods simply marshal data into their native Win32 counterparts and handle any necessary security checks. The Socket class supports two basic modes, synchronous and asynchronous. In synchronous mode, calls to functions that perform network operations (such as Send and Receive) wait until the operation completes before returning control to the calling program. In asynchronous mode, these calls return immediately. 2. Define some terms. (Wikipedia) provides examples of the following API methods
Sockets are usually implemented by an API library such as Berkeley sockets, first introduced in 1983. Most implementations are based on Berkeley sockets, for example Winsock introduced in 1991. Other socket API implementations exist, such as the STREAMS-based Transport Layer Interface (TLI). Development of application programs that utilize this API is called socket programming or network programming. These are examples of functions or methods typically provided by the API library: socket() creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it. bind() is typically used on the server side, and associates a socket with a socket address structure, i.e. a specified local port number and IP address. listen() is used on the server side, and causes a bound TCP socket to enter listening state. connect() is used on the client side, and assigns a free local port number to a socket. In case of a TCP socket, it causes an attempt to establish a new TCP connection. accept() is used on the server side. It accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection. send() and recv(), or write() and read(), or recvfrom() and sendto(), are used for sending and receiving data to/from a remote socket. close() causes the system to release resources allocated to a socket. In case of TCP, the connection is terminated.
3. How is a socket bound to a port number and what is the role of the operating system on the server end? As per the definition given by (Ince, p50), a socket does not exist without the port number. According to (Wikipedia ), the operating system forwards incoming IP packets to the corresponding application or service process by extracting the socket address information from the IP and transport protocol headers 4. Investigate a simple chat client/server system. Look at some program code and describe how it works with multiple users. Here is a vb.net chat server program written in VB that provides information on setting up and implementing a multi user client/server chat system. References Ince, D. (2006). Developing Distributed & E-commerce Applications: Prentice-Hall, Inc. Upper Saddle River, NJ, USA.
MSDN. Sockets. .NET Framework Developer's Guide Retrieved 27 May 2009, from http://msdn.microsoft.com/en-us/library/b6xa24z5.aspx
VB.NET Communications Tutorial. Retrieved 28 May 2009, from http://vb.net-informations.com/communications/vb.net_chat_server_program.htm
Wikipedia. Internet socket. Retrieved 27 May 2009, from http://en.wikipedia.org/wiki/Internet_socket

No comments:

Post a Comment