Sunday, December 11, 2011

Silverlight 5 released !! more access or security threat

Finally it is released. Earlier than expected.
http://www.silverlight.net/learn/overview/what's-new-in-silverlight-5

Nobody said that this is the final version in the Silverlight line as a web technology.But it can be because  Microsoft as a product company started promoting HTML 5.Look at their new OS windows 8. We can even write native windows applications using HTML5 and javascript.

For the developers who still think that Silverlight will be available for long as a web technology, I have a small story .No its not a story its the history of web applications which brought RIA.

The History of RIA

Long long ago when speed of the internet connectivity was in single digit Kb/s, developers created browsers and people started using it. The job of the browser was simple. Get a server address known as URL from the user then retrieve some text from that URL address using socket and port, mainly port 80 and show that text to the user. If the retrieved text contains any markup tags, format the text between the start and end tag according to a name of the tag. That tagging or formatting language known as HTML.

Later there came a scripting language which is executed by the browsers .This make people embed some code which will understand the page and even can modify the web page during runtime. But different browsers supported the language in different ways which made it difficult to write programs.

Years passed .The speed of internet connection started expressing in double digits and at some places the unit Kb/s changed to Mb/s along with the fall of connection cost. Then people started thinking about the shortcomings of the HTML. They figured that if they want to draw a curve there is no inbuilt option to draw other than putting an image which adds load to the downloading content.This also reduce the quality when the same page is opened in big screens with high resolution.Another scenario they faced was lack of an option to refresh small portion of page. This demanded the HTML to support more tags and specifications. The people / panel who decides on HTML told changing the HTML specs is a long process. We cannot change it overnight. It will takes years to evolve. You need to continue using the technology as is.

Some smart people effectively utilized this scenario .They didn't go to change the HTML specifications or the way browser deals with the tags and javascript. They created their own system which has it own run time independent of browser ,programming language, designer applications etc...They just asked browser "Can we get some space in your page?" The browser agreed and in the borrowed space they started playing.

Wow...That was the first impression from people who saw these plug-ins in their browser. Its great,lets put it everywhere.This made a good competition in RIA.RIA is the name given to this technology and it stands for Rich Internet Applications. Investments on RIA technology increased rapidly. Even some people started creating their entire application in RIA excluding the HTML. But one day..

As agreed earlier the governing body of HTML, planned to release specs on new version called HTML 5. This has enough tags to support short comings of old HTML, specification for javascript and much more. The RIA world got panic first but after that it settled down and one of them said that they are stopping their RIA and you can have a tool which will convert your RIA applications to HTML 5. Another RIA vendor said you can even create desktop applications using HTML 5 and Javascript.

Everybody accepted and the world became ready for HTML 5 .Isn't it?

What is next with Silverlight 5


Now Silverlight web developers can directly access so many resources at client side even in the InBrowser mode. From the application developer's view its a great help,but just think from the system admin's / security personal's  view. They need to open up machine to an outside web application which may take up anything from the system or do anything to the system. I agree that there are certificates and other security measures. But don't know why I can't fully agree with this which makes it less different than a desktop application.

I guess in near future if Silverlight as web technology survives HTML 5 ,we can hear about Silverlight VIRUS or some threat which may make it unacceptable. But as a developer I love Silverlight as it is the technology in Windows Phone :-)

Monday, August 29, 2011

Silverlight local messaging issues with ‘\0’

When we want to communicate between 2 Silverlight applications locally, we have a framework way to accomplish the same.Its nothing but 2 classes LocalMessageSender and LocalMessageReceiver.Recently we had faced an issue with local messaging system of Silverlight.The problem was LocalMessageSender sends a message without any exception but when LocalMessageReceiver receives the message, it is not the same message. Its not incorrect data, but the length itself reduced.
We first checked the size of the message which we are sending.It not exceeding 40KB limit as per Microsoft.Then we started digging into the project specifics and could see that the data passed is binary data.ie it’s the data got from a BinarySerializer which is just using the BinaryWriter Class to make the data as binary.The investigation continued to find the character which says the end of the message at the receiver side. After couple of hours I got the character which is nothing but our famous ‘\0’ which was used in C & C++ to denote as end of string.
Our binary serializer was adding this character while serializing the objects. Since the serializer internally uses BinaryWriter, this happens by the BinaryWriter when serializing numbers. I have checked .Net string specification and it says the string is represented using its length rather than the old ‘\0’ style. But don’t know why in local message sending, this is happening.
You can reproduce it simply.Try to send the message "Joy\0George" it will transmit or receives only ‘Joy’.I am not sure which communication end is cutting the message.

private void btnJSON_Click(object sender, RoutedEventArgs e)
{
SendMessage("joy\0George");
}
private void SendMessage(string serialized)
{
MessageBox.Show("Length:"+serialized.Length.ToString());
LocalMessageSender sender = new LocalMessageSender("TestPoint");
sender.SendCompleted += new EventHandler<SendCompletedEventArgs>(sender_SendCompleted);
sender.SendAsync(serialized);
}
void sender_SendCompleted(object sender, SendCompletedEventArgs e)
{
if (e.Error != null) MessageBox.Show(e.Error.ToString());
}





Here is the receiving end.




Private Sub ListenForMessage()
Dim receiver As New LocalMessageReceiver("TestPoint")
AddHandler receiver.MessageReceived, AddressOf Received
receiver.Listen()
End Sub
Private Sub Received(ByVal sender As Object, ByVal e As MessageReceivedEventArgs)
MessageBox.Show("Length " + e.Message.Length.ToString())
DirectCast(sender, IDisposable).Dispose()
End Sub




Don’t confuse with the C# and VB.Net code.All will compile into same ILCode Smile.At the sending side the length will be 10 and receiving end the length will be 3 if we send the above mentioned string which has ‘\0’. 

I can guess that Microsoft uses unmanaged modules to accomplish the communication which takes ‘\0’ as end of string. Anyway I have posted in Silverlight forums.