Creating a chat application using Socket in Silverlight

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'
   2:  
   3: HOST = 'localhost'
   4: PORT = 4505
   5:  
   6: server = TCPServer.new(HOST, PORT)
   7:  
   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:   Thread.new(session) 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

› Continue reading

Compiling and Installing GIT on windows under cygwin

Using GIT was one of the requirements of one of the project that I am doing. Here is how I installed GIT on Windows.

So What is GIT?

The supplied documentation of GIT says that:

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Here is the link for the wikipedia entry.

Where can I download GIT?

Here is the link.

› Continue reading

Friday, April 11th, 2008 FOSS, GIT, cygwin, open source, perl, vista, windows 3 Comments

New and Improved Sudo for Vista (now remembers credentials)

In one of my earlier blog post I shared source code for a simple utility that I had made. It could be used to launch elevated processes from the command line.

So opening a Elevated command prompt was as simple as writing

sudo cmd

Actually the code for this is very simple as it just executes a well documented system function ShellExecute.

I have made some changes to the script and now it remembers the credentials. So once you execute any command, Vista will ask you confirmation only once and any subsequent call won’t ask for the confirmation with the UAC dialog box.

› Continue reading

Wednesday, April 2nd, 2008 security, sudo, vista, vista, security, windows No Comments

Creating Smart Playlists in Windows Media Player

A “Smart  Playlist” is a type of playlist that changes automatically according to criteria you have specified. In Windows Media Player it is called an “Auto Playlist”.

I know that this feature exists in almost every media player but in Windows Media Player this feature is not clearly visible and many people don’t even know anything like this exists.

So here is how you can create a Smart Playlist in Windows Media Player:

Right click on the Playlist button on the left side of the library in window media player and select Create Auto Playlist.

› Continue reading

Using Flex with Ruby on Rails

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.

image

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

› Continue reading

Wednesday, March 26th, 2008 adobe, flex, mxml, rails, ruby, ruby on rails, silverlight, xaml 3 Comments