Creating a chat application using Socket in Silverlight

Posted on April 17, 2008. Filed under: C#, chat application, ruby, silverlight, socket, visual studio 2008 |

Here I will explain how to communicate with the server using the Socket class. The socket class allows Asynchronous communication between the client and server. This application will show how to share data in real-time in two different browser windows using Silverlight.

This application will contain two parts:

  1. Server application using Ruby.
  2. Client application using C# in Silverlight.
Creating the server application:

Making a multi-threaded server application in ruby is really easy and that is the reason I chose Ruby to create the server in least amount of time possible.

   1: require 'socket'
   3: HOST = 'localhost'
   4: PORT = 4505
   6: server =, PORT)
   8: # array to store all the active connections
   9: sessions = []
  10: while (session = server.accept)
  11:   # push the current session(socket) in the array
  12:   sessions << session
  13:   # initialize a new thead for each connection
  14: do |local_session|
  15:     # each time a client sends some data send it to all the connections
  16:     while(true)
  17:       data = local_session.gets
  18:       sessions.each do |s| 
  19:         begin
  20:           s.puts data
  21:         rescue Errno::ECONNRESET
  22:           # an exception is raised, that means the connection to the client is broken
  23:           sessions.delete(s)
  24:         end
  25:       end
  26:     end
  27:   end
  28: end


Here is the pastie.

Save this file as chat_server.rb


Read Full Post | Make a Comment ( 8 so far )

Using Flex with Ruby on Rails

Posted on March 26, 2008. Filed under: adobe, flex, mxml, rails, ruby, ruby on rails, silverlight, xaml |

This is the second blog post in a series of three posts comparing Flex with Silverlight. In my previous post I demonstrated how to integrate a scaffolded Rails application with Silverlight. Here I will be showing the same with Flex. The steps needed to create the Rails application are also mentioned here.


Creating a new Flex project:

Open Flex builder and create a new Flex project.


Leave all the options to default and click Finish. A blank project is now created for you.


Read Full Post | Make a Comment ( 5 so far )

Using Silverlight with Ruby on Rails

Posted on March 26, 2008. Filed under: adobe, C#, crud, flex, microsoft, mxml, rails, ruby, ruby on rails, silverlight, xaml |

In this post I will be showing a really simple example of creating a Silverlight frontend for a Rails backend. This is what I think will be a three part series comparing Silverlight with Flex.

The steps will be:

  1. Creating a Rails application.
  2. Creating a frontend for it in silverlight.
  3. Creating a frontend for it in Flex.
  4. Comparing the approaches taken in both the frontends.

I will try to keep changes in the backend Rails application to a minimum.


Read Full Post | Make a Comment ( 4 so far )

Silverlight 2.0 Beta-1 now available, version 1.0 ported to Nokia mobiles

Posted on March 5, 2008. Filed under: expression blend, microsoft, nokia, silverlight, user interface, xaml |

Microsoft has just released highly anticipated first beta of Silverlight here. The development tools for visual  studio 2008 can be downloaded from here. Tutorials are also available on the same site.

This link reports that Silverlight is now also available on the Nokia mobile devices (specifically S60 on Symbian OS, as well as for Series 40 devices and Nokia Internet tablets). It seems really strange that silverlight wasn’t ported to window mobile devices first. There is a version available for window mobiles as well. I hope it is better than flash lite which really sucks.

If the performance of Silverlight is anywhere near flash then it could be a huge success for Microsoft as .Net as a development platform is already very popular and developers can use their existing skills to create better web experiences. Also IronPython and IronRuby (two of the Silverlight programming languages) are much better (and faster?) languages than Actionscript and .Net provides a much bigger library set.


Read Full Post | Make a Comment ( 2 so far )

Liked it here?
Why not try sites on the blogroll...