Friday, April 20, 2012

Silverlight Windows Phone and Sockets part 1 of an on going learning experience.

So im going to be learning how to write a silverlight app on a windows phone to send gyro data to a pc. Sounds simple, but from the get go I found that the http version of socket is really damn slow, so I'm supposed to use websocket so i've been told. Right now I have an HTTP version of this working which is really slow.

so here it goes. I'm going to read
http://www.rajneeshnoonia.com/blog/2010/12/silverlight-websockets-duplex-communication/
and
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2010/07/27/silverlight-and-websockets.aspx

so hopefully I'll be able to wrap my head around sockets in general by the end of the day.
So websockets allow TCP over a single socket. and Wiki says that any client can use websockets not just browsers. Which is good since im writing a silverlight client. Wiki also mentions "realtime games" which is good since I need to send gyro data as fast as possible from the phone to the pc to use the phone as a controller.

So the wiki technical overview mentions that some browsers dont support this for security reasons, im hoping that the latest version of silverlight im running does support websockets, or im SOL.

Wiki mentions something about a handshake, which is what my fellow programmer mentioned, so it seems like im on the right track. Okay so enough with the wiki, onto the URLs i mentioned.

first with http://mtaulty.com/ he mentions TCP being full duplex and open and closes a connection only at the beginning and end of a session. I want to do this, so again seems like im on the right track. This is better than the http version of the app im working with right now with "using System.Net.Sockets;" in my C# app so far.

he also mentions that i should read http://www.whatwg.org/specs/web-socket-protocol/ but really? it's a gigantic unformatted txt file... WTF? it does mention a lot of UTF8 looking bytes that are line breaks and stuff. so i'll just stick to that being something about the sorts of characters to send to make websockets do specific things.

but what? Now he's talking about http polling and other "tricks" and how great http is making use of sockets. No, i dont want http, it's slow!

okay, hes going back into websockets now. so it's looking like things are back on track....

reading about checking if your browser supports websockets, i'll skip this shit... and he just says use WebSockets open send close methods to use websockets... fucker, that didnt help worth shit.

after further research on msdn I find .NET Framework 4.5 has system.net.websockets, which is what I need, and it's a beta... so lets see if i can get it to work in visual studio 2010 found it here http://www.microsoft.com/download/en/confirmation.aspx?id=28978

i read somewhere that it's not side-by-side compatible with 4.0 so lets hope that the beta mostly works for what I need. since the WebSocket part of the framework is new I'm hoping that they spent a lot of time on this part to make it work right. crossing my fingers...

update ~4pm:
ah! so i found that mtaulty guys video posts which seem a lot more informative http://channel9.msdn.com/blogs/mtaulty/silverlight-4-beta-networking-part-9-udp-multicasting

I installed .NET 4.5 and there's no system.net.winsockets reference to add. I'm not sure what else might have been added but I can't really tell if there's a way to check if 4.5 installed correctly since it just over wrote 4.0 stuff. So I'm going ahead and Installing Visual Studio 2011 beta, so I hope that perhaps that might have the websocket thing I need to add to the project so I can write this client for the phone if the phone can even make use of the new .net libs through silverlight.

update ~7pm:
After installing the Visual Studio 2011 beta I'm met with a rather start grey everything. Kinda neat, but also pretty flat and it feels awkward with the windows 7 glassy frames. And, starting up a project I find I have to go to the on-line templates to find a Windows Phone template that might have what I need. And once I got that up I check for System.Net.Websockets and NOTHING I can't find the reference to add to my phone project. So I'm pretty much dead in the water.

looks like I'll have to write a small javascript web app to websocket data from silverlight to the PC.
We'll take a look at how that might work on monday. For now I'm going to go home and enjoy some Unrealscript and shoot things.

No comments:

Post a Comment

rxokita's shared items