Tuesday, April 24, 2012

WebSockets on the windows Phone 7.1 day 3

Okay, so im sending what I think is a websocket connection attempt. The server logs this out:


Client Connected!!
==================
Client IP 127.0.0.1:60929
TimeStamp: 11:10:14.288
<0> GET
<1> /
<2> HTTP/1.1


<3> Upgrade:
<4> WebSocket


<5> Connection:
<6> Upgrade


<7> Sec-WebSocket-Version:
<8> 13


<9> Sec-WebSocket-Key:
<10> N2M4OWQ3MDgtOGYwNC00MQ==


<11> Host:
<12> 10.10.10.221:11111


<13> Origin:
<14> 10.10.10.221


<15> 


<16> SERVING FILE: ../../../www/index.html TO: 127.0.0.1:60929

So i think it's a http port I'm connecting to, but I'm pretty sure that it might be a web socket since there's all that sec-websocket-version: stuff thats in there. Rather confusing, but I think im getting closer. On the phone side of things I'm checking the websocket status and it's saying "connecting" so i think that's getting closer.

Update: 12pm
Reading up on "subProtocol" i find an RFC which states in the first line in the subProtocol section " _This section is non-normative._" so... This is going to be a very difficult read being that I don't even have any idea what the fuck that sentence even means. Even so, it's saying a sub-protocol is a sub-protocol, which explains nothing. This is why I hate talking to other programmers.


lunch break...
So I managed to notice that the app im sending things to was updating with funny error codes, and it was a bunch of errors coming from the websocket, so that's a good sign. I just have to format the out going stream to something that the websocket message receiver can understand.


the websocket() function is weird.

ws = new WebSocket(("ws://" + hostName + ":" + portNumber));
or
ws = new WebSocket(("ws://" + hostName + ":" + portNumber),"",null,null,"","",WebSocketVersion.DraftHybi00);

Update 3pm
Trying to set the websocket version isnt easy, I have to fill in the rest of the garbage that the method expects. So i'm hoping that the first version works since the more detailed version requires a ton of crap that I don't feel like filling in. AH mother f*cker... so the phone wants to talk in Rfc6455 and server is Hybi00 so i do have to fill in the rest of that shit. damnit...


Update 4:30pm

Yay, managed to fulfill the damn full version of the websocket function. You using string.empty and null you can fill in the junk that doesn't need to be filled right now for testing.


WebSocketVersion ver = WebSocketVersion.DraftHybi00;// <-- need to switch to this mode.
string subProt = "HTTP / 1.1";
ws = new WebSocket(("ws://" + hostName + ":" + portNumber), subProt, string.Empty, null, string.Empty,string.Empty,ver);

Finally got the version of the prototcol to be DraftHybi00 which is what the server is expecting. Now im only getting one weird error... but I can at least test the other versions of the websocket. For one thing, subProtocol is a string. What it expected in that string was difficult to find. So just randomly guessing I found on some RFC.

On your own you can replace ("ws://" + hostName + ":" + portNumber) with a regular url as long as you use ws:// instead of http:// then follow the ip address or web address with a : and a port number that makes sense, web is 80 sometimes on your local area network you might use 8181 or soemthing that your websocket server is listening to.

"CONNECT example.com HTTP/1.1"

so i just tried putting "HTTP/1.1" into the subprotocol, nothing complained, so I'm just going to go with that as the subprotocol. Until I can find a better string to use than that I'll stick with it.

horray! looks like the server side is at least saying

RECEIVED NO DATA


RECEIVED NO DATA


RECEIVED NO DATA


When I send a string through my websocket. that means i just need to format a string to send to it!

it's working!

So now i just gotta format my socket data into a form that the server can understand. and in my case it's a custom server thing so there's nothing i can share about it here.

No comments:

Post a Comment

rxokita's shared items