Calling a WebSocket from Silverlight client example code?
The WebSockets samples on the HTML5 Labs site (here) do not include a Silverlight example开发者_高级运维. Perhaps I missed it somewhere?
I’ve tried various calls to make a socket connection but nothing is working. The ready state is staying at “connecting.”
Here’s some code. I have a listener waiting on port 4502 at the same uri as shown below.
ws = new WebSocket("ws://" + uriString);
ws.OnOpen += new EventHandler<EventArgs>(ws_OnOpen);
ws.Open();
void ws_OnOpen(object sender, EventArgs e)
{
ws.SendMessage(myMessage);
}
Looking at Fiddler, I don’t see any calls being made.
Has anyone tried the prototype code from a SL client?
It should be a Javascript wrap of Silverlight WebSocket.
You also can take a look at WebSocket4Net, which is a C# websocket which has a Silverlight implementation.
It turns out that the WebSocket object was falling out of scope and thus being disposed.
精彩评论