<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Reflections on Expressions</title>
	<atom:link href="http://reflexp.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://reflexp.wordpress.com</link>
	<description>Themes in software development</description>
	<lastBuildDate>Fri, 02 Jan 2009 06:05:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='reflexp.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Reflections on Expressions</title>
		<link>http://reflexp.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://reflexp.wordpress.com/osd.xml" title="Reflections on Expressions" />
	<atom:link rel='hub' href='http://reflexp.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Sockets &#8211; Drilldown</title>
		<link>http://reflexp.wordpress.com/2008/03/23/sockets-drilldown/</link>
		<comments>http://reflexp.wordpress.com/2008/03/23/sockets-drilldown/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 07:25:15 +0000</pubDate>
		<dc:creator>Chandra Sivaraman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://reflexp.wordpress.com/?p=11</guid>
		<description><![CDATA[What Is a Socket? Normally, a server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request. On the client-side: The client knows the hostname of the machine on which the server [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=11&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What Is a Socket?</p>
<p>Normally, a server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request.</p>
<p>On the client-side: The client knows the hostname of the machine on which the server is running and the port number on which the server is listening. To make a connection request, the client tries to rendezvous with the server on the server&#8217;s machine and port. The client also needs to identify itself to the server so it binds to a local port number that it will use during this connection. This is usually assigned by the system.</p>
<p align="center"> </p>
<p>If everything goes well, the server accepts the connection. Upon acceptance, the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client. It needs a new socket so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client.</p>
<p align="center"> </p>
<p>On the client side, if the connection is accepted, a socket is successfully created and the client can use the socket to communicate with the server.</p>
<p>The client and server can now communicate by writing to or reading from their sockets.</p>
<hr size="2" /><strong>Definition:</strong>  A <em>socket</em> is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.</p>
<hr size="2" />An endpoint is a combination of an IP address and a port number. Every TCP connection can be uniquely identified by its two endpoints. That way you can have multiple connections between your host and the server.</p>
<p><strong>Reading from and Writing to a Socket</strong></p>
<p>Let&#8217;s look at a simple example that illustrates how a program can establish a connection to a server program using the <code>Socket</code> class and then, how the client can send data to and receive data from the server through the socket.</p>
<p>The example program implements a client, <code>EchoClient</code>, that connects to the Echo server. The Echo server simply receives data from its client and echoes it back. The Echo server is a well-known service that clients can rendezvous with on port 7.</p>
<p><code>EchoClient</code> creates a socket thereby getting a connection to the Echo server. It reads input from the user on the standard input stream, and then forwards that text to the Echo server by writing the text to the socket. The server echoes the input back through the socket to the client. The client program reads and displays the data passed back to it from the server:</p>
<pre>import java.io.*; import java.net.*;   public class EchoClient {     public static void main(String[] args) throws IOException {           Socket echoSocket = null;         PrintWriter out = null;         BufferedReader in = null;           try {             echoSocket = new Socket("taranis", 7);             out = new PrintWriter(echoSocket.getOutputStream(), true);             in = new BufferedReader(new InputStreamReader(                                         echoSocket.getInputStream()));         } catch (UnknownHostException e) {             System.err.println("Don't know about host: taranis.");             System.exit(1);         } catch (IOException e) {             System.err.println("Couldn't get I/O for "                                + "the connection to: taranis.");             System.exit(1);         }           BufferedReader stdIn = new BufferedReader(                                    new InputStreamReader(System.in));         String userInput;           while ((userInput = stdIn.readLine()) != null) {             out.println(userInput);             System.out.println("echo: " + in.readLine());         }           out.close();         in.close();         stdIn.close();         echoSocket.close();     } }</pre>
<p>Note that <code>EchoClient</code> both writes to and reads from its socket, thereby sending data to and receiving data from the Echo server.</p>
<p>Let&#8217;s walk through the program and investigate the interesting parts. The three statements in the <code>try</code> block of the <code>main</code> method are critical. These lines establish the socket connection between the client and the server and open a <code>PrintWriter</code> and a <code>BufferedReader</code> on the socket:</p>
<pre>echoSocket = new Socket("taranis", 7); out = new PrintWriter(echoSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(                              echoSocket.getInputStream()));</pre>
<p>The first statement in this sequence creates a new <code>Socket</code> object and names it <code>echoSocket</code>. The <code>Socket</code> constructor used here requires the name of the machine and the port number to which you want to connect. The example program uses the host name <code>taranis</code>. This is the name of a hypothetical machine on our local network. When you type in and run this program on your machine, change the host name to the name of a machine on your network. Make sure that the name you use is the fully qualified IP name of the machine to which you want to connect. The second argument is the port number. Port number 7 is the port on which the Echo server listens.</p>
<p>The second statement gets the socket&#8217;s output stream and opens a <code>PrintWriter</code> on it. Similarly, the third statement gets the socket&#8217;s input stream and opens a <code>BufferedReader</code> on it. The example uses readers and writers so that it can write Unicode characters over the socket.</p>
<p>To send data through the socket to the server, <code>EchoClient</code> simply needs to write to the <code>PrintWriter</code>. To get the server&#8217;s response, <code>EchoClient</code> reads from the <code>BufferedReader</code>. The rest of the program achieves this. If you are not yet familiar with the Java platform&#8217;s I/O classes, you may wish to read <a href="http://java.sun.com/docs/books/tutorial/essential/io/index.html" target="_top">Basic I/O</a>.</p>
<p>The next interesting part of the program is the <code>while</code> loop. The loop reads a line at a time from the standard input stream and immediately sends it to the server by writing it to the <code>PrintWriter</code> connected to the socket:</p>
<pre>String userInput;   while ((userInput = stdIn.readLine()) != null) {     out.println(userInput);     System.out.println("echo: " + in.readLine()); }</pre>
<p>The last statement in the <code>while</code> loop reads a line of information from the <code>BufferedReader</code> connected to the socket. The <code>readLine</code> method waits until the server echoes the information back to <code>EchoClient</code>. When <code>readline</code> returns, <code>EchoClient</code> prints the information to the standard output.</p>
<p>The <code>while</code> loop continues until the user types an end-of-input character. That is, <code>EchoClient</code> reads input from the user, sends it to the Echo server, gets a response from the server, and displays it, until it reaches the end-of-input. The <code>while</code> loop then terminates and the program continues, executing the next four lines of code:</p>
<pre>out.close(); in.close(); stdIn.close(); echoSocket.close();</pre>
<p>These lines of code fall into the category of housekeeping. A well-behaved program always cleans up after itself, and this program is well-behaved. These statements close the readers and writers connected to the socket and to the standard input stream, and close the socket connection to the server. The order here is important. You should close any streams connected to a socket before you close the socket itself.</p>
<p>This client program is straightforward and simple because the Echo server implements a simple protocol. The client sends text to the server, and the server echoes it back. When your client programs are talking to a more complicated server such as an HTTP server, your client program will also be more complicated. However, the basics are much the same as they are in this program:</p>
<ol type="1">
<li>Open a socket.</li>
<li>Open an input stream and      output stream to the socket.</li>
<li>Read from and write to the      stream according to the server&#8217;s protocol.</li>
<li>Close the streams.</li>
<li>Close the socket.</li>
</ol>
<p>Only step 3 differs from client to client, depending on the server. The other steps remain largely the same.</p>
<p>Writing the Server Side of a Socket</p>
<p>This section shows you how to write a server and the client that goes with it. The server in the client/server pair serves up Knock Knock jokes. Knock Knock jokes are favored by children and are usually vehicles for bad puns. They go like this:</p>
<p><strong>Server</strong>: &#8220;Knock knock!&#8221;<br />
<strong>Client</strong>: &#8220;Who&#8217;s there?&#8221;<br />
<strong>Server</strong>: &#8220;Dexter.&#8221;<br />
<strong>Client</strong>: &#8220;Dexter who?&#8221;<br />
<strong>Server</strong>: &#8220;Dexter halls with boughs of holly.&#8221;<br />
<strong>Client</strong>: &#8220;Groan.&#8221;</p>
<p>The example consists of two independently running Java programs: the client program and the server program. The client program is implemented by a single class, <code>KnockKnockClient</code>, and is very similar to the <a href="http://java.sun.com/docs/books/tutorial/networking/sockets/examples/EchoClient.java" target="_blank"><code>EchoClient</code></a> example from the previous section. The server program is implemented by two classes: <code>KnockKnockServer</code> and <code>KnockKnockProtocol</code>, <code>KnockKnockServer</code> contains the <code>main</code> method for the server program and performs the work of listening to the port, establishing connections, and reading from and writing to the socket. <code>KnockKnockProtocol</code> serves up the jokes. It keeps track of the current joke, the current state (sent knock knock, sent clue, and so on), and returns the various text pieces of the joke depending on the current state. This object implements the protocol-the language that the client and server have agreed to use to communicate.</p>
<p>The following section looks in detail at each class in both the client and the server and then shows you how to run them.</p>
<h3>The Knock Knock Server</h3>
<p>This section walks through the code that implements the Knock Knock server program. Here is the complete source for the <a href="http://java.sun.com/docs/books/tutorial/networking/sockets/examples/KnockKnockServer.java" target="_blank"><code>KnockKnockServer</code></a> class.</p>
<p>The server program begins by creating a new <code>ServerSocket</code> object to listen on a specific port (see the statement in bold in the following code segment). When writing a server, choose a port that is not already dedicated to some other service. <code>KnockKnockServer</code> listens on port 4444 because 4 happens to be my favorite number and port 4444 is not being used for anything else in my environment:</p>
<pre>try {     <strong>serverSocket = new ServerSocket(4444);</strong> } catch (IOException e) {     System.out.println("Could not listen on port: 4444");     System.exit(-1); }</pre>
<p><code>ServerSocket</code> is a <code>java.net</code> class that provides a system-independent implementation of the server side of a client/server socket connection. The constructor for <code>ServerSocket</code> throws an exception if it can&#8217;t listen on the specified port (for example, the port is already being used). In this case, the <code>KnockKnockServer</code> has no choice but to exit.</p>
<p>If the server successfully binds to its port, then the <code>ServerSocket</code> object is successfully created and the server continues to the next step&#8211;accepting a connection from a client (shown in bold):</p>
<pre>Socket clientSocket = null; try {     <strong>clientSocket = serverSocket.accept();</strong> } catch (IOException e) {     System.out.println("Accept failed: 4444");     System.exit(-1); }</pre>
<p>The <code>accept</code> method waits until a client starts up and requests a connection on the host and port of this server (in this example, the server is running on the hypothetical machine taranis on port 4444). When a connection is requested and successfully established, the accept method returns a new <code>Socket</code> object which is bound to the same local port and has it&#8217;s remote address and remote port set to that of the client. The server can communicate with the client over this new <code>Socket</code> and continue to listen for client connection requests on the original <code>ServerSocket</code> This particular version of the program doesn&#8217;t listen for more client connection requests. However, a modified version of the program is provided in <a href="http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html#later">Supporting Multiple Clients</a>.</p>
<p>After the server successfully establishes a connection with a client, it communicates with the client using this code:</p>
<pre>PrintWriter out = new PrintWriter(                       clientSocket.getOutputStream(), true); BufferedReader in = new BufferedReader(                         new InputStreamReader(                             clientSocket.getInputStream())); String inputLine, outputLine;   <strong>// initiate conversation with client</strong> <strong>KnockKnockProtocol kkp = new KnockKnockProtocol();</strong> <strong>outputLine = kkp.processInput(null);</strong> <strong>out.println(outputLine);</strong>   while ((inputLine = in.readLine()) != null) {      outputLine = kkp.processInput(inputLine);     out.println(outputLine);     if outputLine.equals("Bye."))         break; }</pre>
<p>This code:</p>
<p>1.      Gets the socket&#8217;s input and output stream and opens readers and writers on them.</p>
<p>2.      Initiates communication with the client by writing to the socket (shown in bold).</p>
<p>3.      Communicates with the client by reading from and writing to the socket (the <code>while</code> loop).</p>
<p>Step 1 is already familiar. Step 2 is shown in bold and is worth a few comments. The bold statements in the code segment above initiate the conversation with the client. The code creates a <code>KnockKnockProtocol</code> object-the object that keeps track of the current joke, the current state within the joke, and so on.</p>
<p>After the <code>KnockKnockProtocol</code> is created, the code calls <code>KnockKnockProtocol</code>&#8216;s <code>processInput</code> method to get the first message that the server sends to the client. For this example, the first thing that the server says is &#8220;Knock! Knock!&#8221; Next, the server writes the information to the <code>PrintWriter</code> connected to the client socket, thereby sending the message to the client.</p>
<p>Step 3 is encoded in the <code>while</code> loop. As long as the client and server still have something to say to each other, the server reads from and writes to the socket, sending messages back and forth between the client and the server.</p>
<p>The server initiated the conversation with a &#8220;Knock! Knock!&#8221; so afterwards the server must wait for the client to say &#8220;Who&#8217;s there?&#8221; As a result, the while loop iterates on a read from the input stream. The readLine method waits until the client responds by writing something to its output stream (the server&#8217;s input stream). When the client responds, the server passes the client&#8217;s response to the <code>KnockKnockProtocol</code> object and asks the <code>KnockKnockProtocol</code> object for a suitable reply. The server immediately sends the reply to the client via the output stream connected to the socket, using a call to println. If the server&#8217;s response generated from the <code>KnockKnockServer</code> object is &#8220;Bye.&#8221; this indicates that the client doesn&#8217;t want any more jokes and the loop quits.</p>
<p>The <code>KnockKnockServer</code> class is a well-behaved server, so the last several lines of this section of <code>KnockKnockServer</code> clean up by closing all of the input and output streams, the client socket, and the server socket:</p>
<pre>out.close(); in.close(); clientSocket.close(); serverSocket.close();</pre>
<h3>The Knock Knock Protocol</h3>
<p>The <a href="http://java.sun.com/docs/books/tutorial/networking/sockets/examples/KnockKnockProtocol.java" target="_blank"><code>KnockKnockProtocol</code></a> class implements the protocol that the client and server use to communicate. This class keeps track of where the client and the server are in their conversation and serves up the server&#8217;s response to the client&#8217;s statements. The <code>KnockKnockServer</code> object contains the text of all the jokes and makes sure that the client gives the proper response to the server&#8217;s statements. It wouldn&#8217;t do to have the client say &#8220;Dexter who?&#8221; when the server says &#8220;Knock! Knock!&#8221;</p>
<p>All client/server pairs must have some protocol by which they speak to each other; otherwise, the data that passes back and forth would be meaningless. The protocol that your own clients and servers use depends entirely on the communication required by them to accomplish the task.</p>
<h3>The Knock Knock Client</h3>
<p>The <a href="http://java.sun.com/docs/books/tutorial/networking/sockets/examples/KnockKnockClient.java" target="_blank"><code>KnockKnockClient</code></a> class implements the client program that speaks to the <code>KnockKnockServer</code>. <code>KnockKnockClient</code> is based on the <code>EchoClient</code> program in the previous section, <a href="http://java.sun.com/docs/books/tutorial/networking/sockets/readingWriting.html">Reading from and Writing to a Socket</a> and should be somewhat familiar to you. But we&#8217;ll go over the program anyway and look at what&#8217;s happening in the client in the context of what&#8217;s going on in the server.</p>
<p>When you start the client program, the server should already be running and listening to the port, waiting for a client to request a connection. So, the first thing the client program does is to open a socket that is connected to the server running on the hostname and port specified:</p>
<pre><strong>kkSocket = new Socket("taranis", 4444);</strong> out = new PrintWriter(kkSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(                             kkSocket.getInputStream()));</pre>
<p>When creating its socket, <code>KnockKnockClient</code> uses the host name <code>taranis</code>, the name of a hypothetical machine on our network. When you type in and run this program, change the host name to the name of a machine on your network. This is the machine on which you will run the <code>KnockKnockServer</code>.</p>
<p>The <code>KnockKnockClient</code> program also specifies the port number 4444 when creating its socket. This is a <em>remote port number</em>&#8211;the number of a port on the server machine&#8211;and is the port to which <code>KnockKnockServer</code> is listening. The client&#8217;s socket is bound to any available <em>local port</em>&#8211;a port on the client machine. Remember that the server gets a new socket as well. That socket is bound to local port number 4444 on its machine. The server&#8217;s socket and the client&#8217;s socket are connected.</p>
<p>Next comes the while loop that implements the communication between the client and the server. The server speaks first, so the client must listen first. The client does this by reading from the input stream attached to the socket. If the server does speak, it says &#8220;Bye.&#8221; and the client exits the loop. Otherwise, the client displays the text to the standard output and then reads the response from the user, who types into the standard input. After the user types a carriage return, the client sends the text to the server through the output stream attached to the socket.</p>
<pre>while ((fromServer = in.readLine()) != null) {     System.out.println("Server: " + fromServer);     if (fromServer.equals("Bye."))         break;     fromUser = stdIn.readLine();     if (fromUser != null) {         System.out.println("Client: " + fromUser);         out.println(fromUser);     } }</pre>
<p>The communication ends when the server asks if the client wishes to hear another joke, the client says no, and the server says &#8220;Bye.&#8221;</p>
<p>In the interest of good housekeeping, the client closes its input and output streams and the socket:</p>
<pre>out.close(); in.close(); stdIn.close(); kkSocket.close();</pre>
<h3>Running the Programs</h3>
<p>You must start the server program first. To do this, run the server program using the Java interpreter, just as you would any other Java application. Remember to run the server on the machine that the client program specifies when it creates the socket.</p>
<p>Next, run the client program. Note that you can run the client on any machine on your network; it does not have to run on the same machine as the server.</p>
<p>If you are too quick, you might start the client before the server has a chance to initialize itself and begin listening on the port. If this happens, you will see a stack trace from the client. If this happens, just restart the client.</p>
<p>If you forget to change the host name in the source code for the <code>KnockKnockClient</code> program, you will see the following error message:</p>
<pre>Don't know about host: taranis</pre>
<p>To fix this, modify the <code>KnockKnockClient</code> program and provide a valid host name for your network. Recompile the client program and try again.</p>
<p>If you try to start a second client while the first client is connected to the server, the second client just hangs. The next section, <a href="http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html#later%22">Supporting Multiple Clients</a>, talks about supporting multiple clients.</p>
<p>When you successfully get a connection between the client and server, you will see the following text displayed on your screen:</p>
<pre>Server: Knock! Knock!</pre>
<p>Now, you must respond with:</p>
<pre><strong>Who's there?</strong></pre>
<p>The client echoes what you type and sends the text to the server. The server responds with the first line of one of the many Knock Knock jokes in its repertoire. Now your screen should contain this (the text you typed is in bold):</p>
<pre>Server: Knock! Knock! <strong>Who's there?</strong> Client: Who's there? Server: Turnip</pre>
<p>Now, you respond with:</p>
<pre>Turnip who?"</pre>
<p>Again, the client echoes what you type and sends the text to the server. The server responds with the punch line. Now your screen should contain this:</p>
<pre>Server: Knock! Knock! <strong>Who's there?</strong> Client: Who's there? Server: Turnip <strong>Turnip who?</strong> Client: Turnip who? Server: Turnip the heat, it's cold in here! Want another? (y/n)</pre>
<p>If you want to hear another joke, type <strong>y</strong>; if not, type <strong>n</strong>. If you type <strong>y</strong>, the server begins again with &#8220;Knock! Knock!&#8221; If you type <strong>n</strong>, the server says &#8220;Bye.&#8221; thus causing both the client and the server to exit.</p>
<p>If at any point you make a typing mistake, the <code>KnockKnockServer</code> object catches it and the server responds with a message similar to this:</p>
<pre>Server: You're supposed to say "Who's there?"!</pre>
<p>The server then starts the joke over again:</p>
<pre>Server: Try again. Knock! Knock!</pre>
<p>Note that the <code>KnockKnockProtocol</code> object is particular about spelling and punctuation but not about capitalization.</p>
<h3><a name="later"></a>Supporting Multiple Clients</h3>
<p>To keep the <code>KnockKnockServer</code> example simple, we designed it to listen for and handle a single connection request. However, multiple client requests can come into the same port and, consequently, into the same <code>ServerSocket</code>. Client connection requests are queued at the port, so the server must accept the connections sequentially. However, the server can service them simultaneously through the use of threads &#8211; one thread per each client connection.</p>
<p>The basic flow of logic in such a server is this:</p>
<pre>while (true) {     accept a connection ;     create a thread to deal with the client ; end while</pre>
<p>The thread reads from and writes to the client connection as necessary.</p>
<hr size="2" /><strong>Try This:</strong>  Modify the <code>KnockKnockServer</code> so that it can service multiple clients at the same time. Two classes compose our solution: <a href="http://java.sun.com/docs/books/tutorial/networking/sockets/examples/KKMultiServer.java" target="_blank"><code>KKMultiServer</code></a> and <a href="http://java.sun.com/docs/books/tutorial/networking/sockets/examples/KKMultiServerThread.java" target="_blank"><code>KKMultiServerThread</code></a>. <code>KKMultiServer</code> loops forever, listening for client connection requests on a <code>ServerSocket</code>. When a request comes in, <code>KKMultiServer</code> accepts the connection, creates a new <code>KKMultiServerThread</code> object to process it, hands it the socket returned from accept, and starts the thread. Then the server goes back to listening for connection requests. The <code>KKMultiServerThread</code> object communicates to the client by reading from and writing to the socket. Run the new Knock Knock server and then run several clients in succession.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/reflexp.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/reflexp.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/reflexp.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/reflexp.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/reflexp.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/reflexp.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/reflexp.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/reflexp.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/reflexp.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/reflexp.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/reflexp.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/reflexp.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/reflexp.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/reflexp.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/reflexp.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/reflexp.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=11&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://reflexp.wordpress.com/2008/03/23/sockets-drilldown/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/94b0e5e650578569b74309a44efbb4ee?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shekar</media:title>
		</media:content>
	</item>
		<item>
		<title>Floating-point arithmetic</title>
		<link>http://reflexp.wordpress.com/2008/03/23/floating-point-arithmetic/</link>
		<comments>http://reflexp.wordpress.com/2008/03/23/floating-point-arithmetic/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 06:06:29 +0000</pubDate>
		<dc:creator>Chandra Sivaraman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://reflexp.wordpress.com/?p=10</guid>
		<description><![CDATA[Have you ever wondered why seemingly precise floating point numbers such as 0.1 are internally stored as 0.100000005960465188081882963405? Well, in a nutshell, the answer is that floating point types use base 2 representation instead of base 10. This means that we only get an approximation even for non-recurring fractional numbers such as 0.1 or 0.345. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=10&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Have you ever wondered why seemingly precise floating point numbers such as 0.1 are internally stored as 0.100000005960465188081882963405?  Well,  in a nutshell,  the answer is that <b>floating point types use base 2 representation instead of base 10</b>.  This means that we only get an approximation even for non-recurring fractional numbers such as 0.1 or 0.345.</p>
<p>This topic is examined in excruciating detail in this <a href="http://blogs.msdn.com/bclteam/archive/2007/05/29/bcl-refresher-floating-point-types-the-good-the-bad-and-the-ugly-inbar-gazit-matthew-greig.aspx" target="_blank">posting</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/reflexp.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/reflexp.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/reflexp.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/reflexp.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/reflexp.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/reflexp.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/reflexp.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/reflexp.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/reflexp.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/reflexp.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/reflexp.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/reflexp.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/reflexp.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/reflexp.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/reflexp.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/reflexp.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=10&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://reflexp.wordpress.com/2008/03/23/floating-point-arithmetic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/94b0e5e650578569b74309a44efbb4ee?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shekar</media:title>
		</media:content>
	</item>
		<item>
		<title>Adapter pattern</title>
		<link>http://reflexp.wordpress.com/2007/12/30/adapter-pattern/</link>
		<comments>http://reflexp.wordpress.com/2007/12/30/adapter-pattern/#comments</comments>
		<pubDate>Sun, 30 Dec 2007 20:18:34 +0000</pubDate>
		<dc:creator>Chandra Sivaraman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://reflexp.wordpress.com/2007/12/30/adapter-pattern/</guid>
		<description><![CDATA[When I take electronic equipment purchased in the USA to India, I can&#8217;t plug them directly into the electrical outlets over there. Even if my power cable has a transformer that steps down the 240V to 110V, the plug won&#8217;t fit the socket. My problem can be solved by using a very simple electrical device [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=9&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When I take electronic equipment purchased in the USA to India,  I can&#8217;t plug them directly into the electrical outlets over there.  Even if my power cable has a transformer that steps down the 240V to 110V,  the plug won&#8217;t fit the socket.  My problem can be solved by using a very simple electrical device called an adapter.  It has a US style socket on one side for plugging in my equipment and an Indian style plug on the other side that fits into the Indian outlet.</p>
<p>The same principle is employed in software design to solve the problem of mismatching interfaces between two classes.  For e.g. you have a task manager that defines interfaces for task object plug-ins.  You need to plug in a 3rd party email task object which has its own interface.  To get the task manager to talk to the email plugin, you need to create an email adapter class that implements the interface that the task manager is expecting, and then routes method calls on that interface to the email plugin.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/reflexp.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/reflexp.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/reflexp.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/reflexp.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/reflexp.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/reflexp.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/reflexp.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/reflexp.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/reflexp.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/reflexp.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/reflexp.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/reflexp.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/reflexp.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/reflexp.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/reflexp.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/reflexp.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=9&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://reflexp.wordpress.com/2007/12/30/adapter-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/94b0e5e650578569b74309a44efbb4ee?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shekar</media:title>
		</media:content>
	</item>
		<item>
		<title>Hash functions</title>
		<link>http://reflexp.wordpress.com/2007/12/29/hash-functions/</link>
		<comments>http://reflexp.wordpress.com/2007/12/29/hash-functions/#comments</comments>
		<pubDate>Sat, 29 Dec 2007 23:49:47 +0000</pubDate>
		<dc:creator>Chandra Sivaraman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://reflexp.wordpress.com/2007/12/29/hash-functions/</guid>
		<description><![CDATA[A hash function maps keys onto array indices. A good hash function ensures an even distribution of keys onto indices, avoiding excessive chaining which can degrade hash table performance. A sample program that can be used to test the effectiveness of hash functions : using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Hashfunction { [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=8&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A hash function maps keys onto array indices.   A good hash function ensures an even distribution of keys onto indices, avoiding excessive chaining which can degrade hash table performance.</p>
<p>A sample program that can be used to test the effectiveness of hash functions :</p>
<pre><code>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hashfunction
{
    class SomeType
    {
        public SomeType(int i) { m_i = i; }
        public override int GetHashCode()
        {
            return m_i % 7009;
        }

        private int m_i;
    }

    class Program
    {
        static void Main(string[] args)
        {
            Random rand = new Random(1028309);
            int maxVal = 1000;

            int[] dist = new int[maxVal];

            // Generate 1000 random keys. compute hash func for each key and
            // add it to an array to measure distribution
            for (int i = 1; i &lt; maxVal; i++)
            {
                int k = rand.Next(maxVal);
                SomeType t = new SomeType (k);
                int h = t.GetHashCode();
                Console.WriteLine("k = {0}, h(k) = {1}", k, h);

                dist[h]++;
            }

            // Output the hash function distribution
            for(int i=0; i&lt;dist.Length; i++)
            {
                Console.Write("{0} |",i);
                for(int j=0;j&lt;dist[i];j++)
                    Console.Write("*");
                Console.WriteLine();
            }

        }
    }
}</code></pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/reflexp.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/reflexp.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/reflexp.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/reflexp.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/reflexp.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/reflexp.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/reflexp.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/reflexp.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/reflexp.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/reflexp.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/reflexp.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/reflexp.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/reflexp.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/reflexp.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/reflexp.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/reflexp.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=8&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://reflexp.wordpress.com/2007/12/29/hash-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/94b0e5e650578569b74309a44efbb4ee?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shekar</media:title>
		</media:content>
	</item>
		<item>
		<title>What is a design pattern?</title>
		<link>http://reflexp.wordpress.com/2007/12/29/what-is-a-design-pattern/</link>
		<comments>http://reflexp.wordpress.com/2007/12/29/what-is-a-design-pattern/#comments</comments>
		<pubDate>Sat, 29 Dec 2007 21:52:03 +0000</pubDate>
		<dc:creator>Chandra Sivaraman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://reflexp.wordpress.com/2007/12/29/what-is-a-design-pattern/</guid>
		<description><![CDATA[From Wikipedia : a design pattern is a general repeatable solution to a commonly occurring problem in software design. Algorithms are not thought of as design patterns, since they solve computational problems rather than design problems. Patterns originated as an architectural concept by Christopher Alexander (1977/79). &#8220;Each pattern describes a problem which occurs over and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=7&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>From Wikipedia :</p>
<p>a <a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)" target="_blank">design pattern</a> is a general repeatable solution to a commonly occurring problem in software design.</p>
<p>Algorithms are not thought of as design patterns, since they solve computational problems rather than design problems.</p>
<p>Patterns originated as an architectural concept by Christopher Alexander (1977/79).<br />
&#8220;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&#8221;.</p>
<p>This was said with reference to architectural patterns, however, holds equally true for software design problems, and indeed any problem space.</p>
<p><b>Anti-patterns</b> are specific repeated practices that appear initially to be beneficial, but ultimately result in bad consequences that outweigh the hoped-for advantages.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/reflexp.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/reflexp.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/reflexp.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/reflexp.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/reflexp.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/reflexp.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/reflexp.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/reflexp.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/reflexp.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/reflexp.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/reflexp.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/reflexp.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/reflexp.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/reflexp.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/reflexp.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/reflexp.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=7&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://reflexp.wordpress.com/2007/12/29/what-is-a-design-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/94b0e5e650578569b74309a44efbb4ee?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shekar</media:title>
		</media:content>
	</item>
		<item>
		<title>Data patterns</title>
		<link>http://reflexp.wordpress.com/2007/12/28/data-patterns/</link>
		<comments>http://reflexp.wordpress.com/2007/12/28/data-patterns/#comments</comments>
		<pubDate>Fri, 28 Dec 2007 07:00:48 +0000</pubDate>
		<dc:creator>Chandra Sivaraman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://reflexp.wordpress.com/2007/12/28/data-patterns/</guid>
		<description><![CDATA[MSDN talks about data patterns &#8211; i.e. patterns that manifest when working with data &#8211; moving, transforming, structuring it &#8230; and patterns amongst patterns &#8211; i.e. how patterns use other patterns, derive from each other, refine each other&#8230;. For example, we see how the &#8216;Move Data Copy&#8217; pattern can be refined and used for &#8216;Data [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=5&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://msdn2.microsoft.com/en-us/library/ms998461.aspx">MSDN</a> talks about data patterns &#8211; i.e. patterns that manifest when working with data &#8211; moving, transforming, structuring it &#8230; and patterns amongst patterns &#8211; i.e. how patterns use other patterns, derive from each other, refine each other&#8230;.</p>
<p>For example, we see how the &#8216;Move Data Copy&#8217; pattern can be refined and used for &#8216;Data Replication&#8217;, which in turn refines into &#8216;Master-Slave Replication&#8217; which in turn refines into &#8216;Master-Slave Snapshot Replication&#8217; and &#8216;Master-Slave TransactionalIncremental Replication&#8217;. I can relate this to situations I have encountered in my job: Production database dumps to a secondary server followed by on-demand replication to multiple consumers from the secondary follows the &#8216;Master-Slave cascading replication&#8217; pattern.</p>
<p>As the MSDN write-up says, this :</p>
<p>· ensures that all clients share the same snapshot</p>
<p>· ensures that the primary server is not being unduly loaded to service these data requests</p>
<p>· ensures scalability as the number of consumers increases</p>
<p>· ensures that consumers aren&#8217;t impacted by the availability of the primary server (e.g. primary may be offline duringcertain times of the day for maintenance).</p>
<p>· Minimizes the effects of a slow link between the master and slaves. E.g. the master may be on a different network, and so making a one-time snapshot onto the slave network and then re-distributing it to multipleConsumers On the slave network is much more efficient.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/reflexp.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/reflexp.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/reflexp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/reflexp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/reflexp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/reflexp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/reflexp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/reflexp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/reflexp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/reflexp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/reflexp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/reflexp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/reflexp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/reflexp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/reflexp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/reflexp.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=5&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://reflexp.wordpress.com/2007/12/28/data-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/94b0e5e650578569b74309a44efbb4ee?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shekar</media:title>
		</media:content>
	</item>
		<item>
		<title>Delegates</title>
		<link>http://reflexp.wordpress.com/2007/11/29/delegates/</link>
		<comments>http://reflexp.wordpress.com/2007/11/29/delegates/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 07:36:15 +0000</pubDate>
		<dc:creator>Chandra Sivaraman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://reflexp.wordpress.com/2007/11/29/delegates/</guid>
		<description><![CDATA[A delegate (also known as functor) is a strange beast. It seems to exhibit behavior of a function as well as an object. Satya makes an analogy with wave-particle duality in physics in this lucid article.  Stripped to essentials, a delegate is merely a function pointer packaged up in a class. What benefits does the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=4&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A delegate (also known as functor) is a strange beast.  It seems to exhibit behavior of a function as well as an object.  Satya makes an analogy with wave-particle duality in physics in this lucid <a href="http://www.ondotnet.com/pub/a/dotnet/2002/11/04/delegates.htm" target="_blank"><span class="Apple-style-span" style="color:#000000;text-decoration:none;">article</span></a>.  Stripped to essentials, a delegate is merely a function pointer packaged up in a class.</p>
<p>What benefits does the class bring?  To start with, it allows us to pass meaningful data along with the function pointer &#8211;  to indicate whether the function is static or an instance method,  if instance method,  then the parent object reference.  The class also satisfies the type-safety concerns of the purists.  Other nifty things like transmitting multiple functors through a single delegate are also possible.</p>
<p>Related Design Patterns : <a href="http://en.wikipedia.org/wiki/Command_pattern" target="_blank"><span class="Apple-style-span" style="text-decoration:none;color:#000000;"></span></a></p>
<p><a href="http://en.wikipedia.org/wiki/Command_pattern" target="_blank"><span class="Apple-style-span" style="text-decoration:none;color:#000000;">Command</span></a> &#8211; objects used to represent actions. <a href="http://en.wikipedia.org/wiki/Observer_pattern" target="_blank"><span class="Apple-style-span" style="text-decoration:none;color:#000000;"></span></a><a href="http://en.wikipedia.org/wiki/Observer_pattern" target="_blank"><span class="Apple-style-span" style="text-decoration:none;color:#000000;"></span></a></p>
<p><a href="http://en.wikipedia.org/wiki/Observer_pattern" target="_blank"><span class="Apple-style-span" style="text-decoration:none;color:#000000;">Observer</span></a> &#8211;  publish/subscribe &#8211; Java has a related concept in Listeners.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/reflexp.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/reflexp.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/reflexp.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/reflexp.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/reflexp.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/reflexp.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/reflexp.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/reflexp.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/reflexp.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/reflexp.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/reflexp.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/reflexp.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/reflexp.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/reflexp.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/reflexp.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/reflexp.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=4&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://reflexp.wordpress.com/2007/11/29/delegates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/94b0e5e650578569b74309a44efbb4ee?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shekar</media:title>
		</media:content>
	</item>
		<item>
		<title>Chain of command pattern</title>
		<link>http://reflexp.wordpress.com/2007/11/29/chain-of-command-pattern/</link>
		<comments>http://reflexp.wordpress.com/2007/11/29/chain-of-command-pattern/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 05:31:36 +0000</pubDate>
		<dc:creator>Chandra Sivaraman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://reflexp.wordpress.com/2007/11/29/chain-of-command-pattern/</guid>
		<description><![CDATA[Consider a TCP/IP request being sent over the Internet. The request passes from client to router and through a series of relaying hosts before reaching its ultimate destination. Each intermediate recipient checks to see if it can process the message &#8211; if not, passes it onto the next recipient in the chain. In this manner, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=3&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Consider a TCP/IP request being sent over the Internet.  The request passes from client to router and through a series of relaying hosts before reaching its ultimate destination. Each intermediate recipient checks to see if it can process the message &#8211; if not, passes it onto the next recipient in the chain.  In this manner, the client need not have specific knowledge of the exact route to the destination &#8211; or even who or where the destination is for that matter.</p>
<p>for e.g. a request for a popular URL may be serviced by a local mirror instead of the URL host.</p>
<p>This enables a type of loose coupling between the client and the servicer of the message. In other words,  information about which object to send the request to doesn&#8217;t have to be hardcoded in the client .. the object servicing the request can be dynamically selected or switched at runtime, with the client being none the wiser.</p>
<p>Real-life examples :<br />
MQSTAM task manager&#8217;s task objects implement chain-of-responsibility..</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/reflexp.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/reflexp.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/reflexp.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/reflexp.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/reflexp.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/reflexp.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/reflexp.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/reflexp.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/reflexp.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/reflexp.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/reflexp.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/reflexp.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/reflexp.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/reflexp.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/reflexp.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/reflexp.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=3&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://reflexp.wordpress.com/2007/11/29/chain-of-command-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/94b0e5e650578569b74309a44efbb4ee?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shekar</media:title>
		</media:content>
	</item>
		<item>
		<title>Microsoft Component Technologies &#8211; A Summary</title>
		<link>http://reflexp.wordpress.com/2007/11/27/hello-world/</link>
		<comments>http://reflexp.wordpress.com/2007/11/27/hello-world/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 07:08:31 +0000</pubDate>
		<dc:creator>Chandra Sivaraman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[DDE Dynamic Data Exchange. DDE was the remote ancestor of OLE and COM from the ancient past. It supported IPC between multiple apps. Introduced in 1987 with Windows 2.0. Still used for Shell file associations. NetDDE was DDE with networking support. Was bundled with Windows XP. Removed in Vista. OLE Automation Object Linking and Embedding. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=1&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight:bold;">DDE</span><br />
Dynamic Data Exchange.  DDE was the remote ancestor of OLE and COM from the ancient past.  It supported IPC between multiple apps.  Introduced in 1987 with Windows 2.0.  Still used for Shell file associations.
<div>NetDDE was DDE with networking support.  Was bundled with Windows XP.  Removed in Vista.</p>
<p><span style="font-weight:bold;">OLE Automation</span><br />
Object Linking and Embedding.  Microsoft client-server technology for IPC that allowed an Excel chart to be embedded or linked from a Word document. The shared objects(automation objects) were hosted by an OLE server and could be accessed through an OLE client (automation controller).</p>
<p><span style="font-weight:bold;">COM</span><br />
COM is Microsoft&#8217;s platform for creating software using components &#8211; standardized reusable software blocks callable by a variety of client platforms.</p>
<p>What are the features of a component that come to mind -<br />
run-time type discovery (QueryInterface)<br />
loose coupling/late binding (IDispatch)<br />
dynamic creation and destruction (CoCreateInstance)<br />
isolation from the client process (out of process execution)<br />
lifetime management services (Addref-Release)<br />
multi-platform support (e.g. C++,VB,Scripting)</p>
<p><span style="font-weight:bold;">ATL</span><br />
A set of lightweight template-based C++ classes to simplify COM programming.  MFC was heavy weight and couldn&#8217;t be used for Internet controls.</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/reflexp.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/reflexp.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/reflexp.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/reflexp.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/reflexp.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/reflexp.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/reflexp.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/reflexp.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/reflexp.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/reflexp.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/reflexp.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/reflexp.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/reflexp.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/reflexp.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/reflexp.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/reflexp.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=reflexp.wordpress.com&amp;blog=2211226&amp;post=1&amp;subd=reflexp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://reflexp.wordpress.com/2007/11/27/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/94b0e5e650578569b74309a44efbb4ee?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shekar</media:title>
		</media:content>
	</item>
	</channel>
</rss>
