C#
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:
- Server application using Ruby.
- 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
Save this file as chat_server.rb
Using Silverlight with Ruby on Rails
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:
- Creating a Rails application.
- Creating a frontend for it in silverlight.
- Creating a frontend for it in Flex.
- Comparing the approaches taken in both the frontends.
I will try to keep changes in the backend Rails application to a minimum.
Blogroll
Recent Posts
- Autocompleting ssh, rake, cap command parameters using PowerShell
- Using RubyAmf for creating a CRUD application in Rails
- Multiple ways to open PowerShell in the current Explorer window
- Context sensitive auto-completion using PowerShell, PowerTab and GIT
- Displaying GIT Branch on your PowerShell prompt
XBox Live
Songs I like
Categories
- adobe (4)
- amarok (1)
- C# (2)
- chat application (1)
- crud (2)
- cygwin (1)
- explorer (1)
- expression blend (1)
- flex (4)
- FOSS (2)
- free (1)
- GIT (3)
- ID3 (1)
- java (1)
- microsoft (3)
- mxml (2)
- nokia (1)
- open source (5)
- perl (1)
- powerpoint (2)
- powershell (3)
- rails (3)
- right click (1)
- ruby (9)
- ruby on rails (3)
- security (3)
- silverlight (4)
- smart playlist (1)
- socket (1)
- software (7)
- ssh (1)
- sudo (1)
- tabs (1)
- tomcat (1)
- user interface (6)
- vista (9)
- vista, security (2)
- visual studio 2008 (1)
- win32ole (1)
- windows (13)
- windows media player (1)
- wpf (1)
- xaml (4)
- XP (3)
