Jump to content
Tuts 4 You
LCF-AT

Looking for websocket Client code examples

Recommended Posts

deepzero
1 minute ago, evlncrn8 said:

or male for that matter (that part was pretty pathetic and not required to be honest)...

To clarify, the "men men men" part is a somewhat adorable literal adaption of a German expression and not at all about gender. :)

  • Like 1

Share this post


Link to post
Share on other sites
evlncrn8
Posted (edited)

ah well, that i didnt think about, or the complexities of having to read documentation thats typically not in native language, i stand by the rest of what i wrote though

Edited by evlncrn8 (see edit history)

Share this post


Link to post
Share on other sites
kao

I promised not to post anymore but since flamewar got started by my post, I think I should also finish it.

 

Try to read your topics like someone else would. Then maybe you'll understand my point of view.

Here's how most of your topics look like from where I stand:

1) You ask a question. You don't do it the smart way. You don't tell what is the problem you're trying to solve. Instead, you jump to what you think is a right solution and ask how to implement that. Want an example? See your topic about resource structures. You started by asking how to parse all the structures manually and only after 10-20-whatever posts it turned out you can use standard Windows APIs. Same about HTTP downloads, you started by implementing all HTTP protocol manually over winsock, ended up with using winhttp/urlmon/whatever APIs. And all this time members of this board spend their time to find solutions for you - which turn out to be overly complicated and unnecessary;

2) When someone give you a perfectly valid suggestion of what you could do, you find ten excuses why you will not take that advice and do it another way.  Fine by me, but then why did you ask for help in the first place? I spent quite a lot of time researching answers to that question, trying to find the best answer for you. And that time seems to be wasted.

3) Then you do that thing "your way". It - quite predictably - doesn't work. You complain. A lot. About things you can't change anyway. Just search your topics for phrases like "this sucks" or "thats BS" or similar. That's not constructive or helping in any way, just annoying.

4) Then you ask for an example code in MASM. Because you claim it's the only language you can understand. Nobody uses complex libraries with ASM these days, so there is almost no code to be found. So, members of this board do the next best thing - find you examples in the different language, usually C. You complain. A lot. Because you can't compile the example. Because downloading free Visual Studio Community Edition and free Microsoft SDKs is such a chore.. Repeat the step few times.

5) Finally you get the example code working. You quickly write your own code in ASM. It doesn't work. Instead of reading source code/debugging the compiled example and getting an understanding why it works and your code doesn't, you complain that the XYZ library sucks, the documentation is useless and everything is crap. The solution is somewhere in the example source code, documentation or found with less than 5 Google searches. Repeat the step until the end of the topic.

 

Sure, these are your topics and you can do whatever you want. But I just don't want to be any part of that anymore. 

Now let us all get back to reversing/coding/whatever else we were doing before the interruption... Peace!

Share this post


Link to post
Share on other sites
LCF-AT

Hi,

didnt I told you that the docs and whole client example code wasnt helpfully for me build a working example?I think so and thats also the problem I tried to solve.If I have any questions then I use this forum (if I cant handle it by myself yet) to get some helpfully answers.I dont have any problem with that.Some people need some help to any theme and some give some help if they can with the right matching context which can be simple till complex.I dont wanna hear answers like read the docs / manual if I told already that I did and have problems with that.Its nice to hear that its for you no problem to read that "Fabulous" manual like a shopping list where I can just say congratulations to you but I cant you know.Thats the diffrent.Some people can and some not or not so good.I know that you are one of the smartest person who know almost everything about PC inside / outside stuff kao,(thats the reason I called you super brain [of course not in a pathetic way as evlncrn8 thought]) because for you its no problem and maybe you work with PC stuff 24/7 and I do not.I mostly try also to ask pretty simple in the hope that most do also understand what I mean and to get some simple answers back in return.

Yes I like to use phrases like BS / this sucks or something like that just because I am a human with emotions and I dont hide them also if they are not productive to fix any problem.I am not a robot or android like Data.

Some other questions are pretty simple to understand,so if anyone wanna help then you can read it in the answer/s between the lines.In your case I can mostly just read some kind of contempt not just since yesterday what makes me angry.Just my opinion of course.

Anyway,so nobody told or forced you to be part of my "stupid asking topic/s" but if you already know what comes out at the end then you should better not start the process.

greetz

Share this post


Link to post
Share on other sites
evlncrn8
Posted (edited)

can you get visual studio, and install it and the libs so that wont be a problem in the future though ? 

cos, i do get the 'do it in asm / pure language / whatnot', and i too was once like you a coding purist, then x64 came along and changed things a lot.. 

for small projects managing some asm and porting it to x64 asm might be relatively easy, but there are so many overheads its a lot easier to do most of the core in c/c++, and if you must code a function / portion for speed do it in asm sure, but just that bit... but honestly, the compilers these days are pretty damn good and could probably optimise the hell out of c code potentially better than any hand written asm you might make.. 

and for that reason im mostly doing pid in c/c++ now, with just the main 'engine' routines in asm (if they are needed to be in asm)...

the days of optimising for size are long gone, look how bloated the os is even.. let alone crap like .net at 20mb+ for the framework alone

same could be argued for speed, the processors now are considerably faster than in the old 80386 days... a lot has progressed on / modernised, perhaps your way of thinking / coding should too, as the os you're using is pretty much all (except for specific .. minimal components) c... 

Edited by evlncrn8 (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites
LCF-AT

Hi again,

hhmm.Thank so far.I will see whether I try to install that visual studio and trying to use it anyhow and see whether I can do something with that (not sure so I am no expert on this field you know).Yes I see almost everything is written in c/c++ these days.

I still have questions about that websocket issues I have.I tried to write another new code with the example websocket address I did post before using nopoll functions.My new code seem to get a connection to the server but the only thing I get from there is a PING string.If I check the connection in Opera browser / websocket tab / frames then I see what the browser did send and  received.There I can also see a PING message which was answered with a PONG message by browser.Also other messages I can see there.My question is what I need to send and  whether I have to send something or some specific strings first etc?On internet I found something about heatbeat = server sends a PING to check whether client (me) is still alive and is waiting for a answer from me = I send a PONG.Of course I still dont understand the whole process of getting / sending datas.

My test code is this so far...without sending any string/s PONG etc.

W2 proc hwnd:DWORD
local ctx:DWORD
local conn:DWORD
local msg:DWORD
local opts:DWORD

nop
nop
nop
    invoke nopoll_ctx_new
    mov ctx, eax
    invoke nopoll_conn_opts_new
    mov opts, eax
    invoke nopoll_conn_opts_ssl_peer_verify,opts,nopoll_false
    invoke nopoll_conn_tls_new,ctx,opts,chr$("sapi-ws-1x03.vaughnsoft.net"),chr$("443"),0,0,0,0
    mov conn, eax
    invoke nopoll_conn_is_ok,conn
    .if eax == nopoll_false
        invoke MessageBox,hwnd,chr$("nopoll_conn_is_ok 1 - fails!"),chr$("Problem!"),MB_ICONWARNING
        invoke nopoll_conn_close,conn
        invoke nopoll_ctx_unref,ctx
        mov eax, nopoll_false
        ret    
    .endif
    
@@:
    invoke nopoll_conn_wait_until_connection_ready,conn,5
    .if eax == nopoll_false
        invoke GetLastError
        .if eax != WSAEWOULDBLOCK
        invoke MessageBox,hwnd,chr$("nopoll_conn_wait_until_connection_ready - fails!"),chr$("Problem!"),MB_ICONWARNING
        invoke nopoll_conn_close,conn
        invoke nopoll_ctx_unref,ctx
        mov eax, nopoll_false
        ret
        .endif
        invoke nopoll_sleep,10000
        jmp @B        
    .endif
    
    
    xor edi,edi
    .while edi == 0h
    invoke nopoll_conn_is_ready,conn
    mov edi, eax
        .if eax == nopoll_false
            invoke nopoll_conn_is_ok,conn
            .if eax == nopoll_false
                invoke MessageBox,hwnd,chr$("nopoll_conn_is_ok 2 - fails!"),chr$("Problem!"),MB_ICONWARNING
                invoke nopoll_conn_close,conn
                invoke nopoll_ctx_unref,ctx
                mov eax, nopoll_false
                ret             
            .else
                invoke nopoll_sleep,10000
            .endif
        .endif
    .endw
    
    invoke nopoll_conn_is_tls_on,conn
    .if eax == nopoll_false
        invoke MessageBox,hwnd,chr$("nopoll_conn_is_tls_on - fails!"),chr$("Problem!"),MB_ICONWARNING
        invoke nopoll_conn_close,conn
        invoke nopoll_ctx_unref,ctx
        mov eax, nopoll_false
        ret          
    .endif
    
@@:
    xor edi,edi
    .while edi == 0h
    invoke nopoll_conn_get_msg,conn
    mov edi, eax
    mov msg, eax
        .if edi != nopoll_false
            .break
        .endif
        invoke nopoll_conn_is_ok,conn
        .if eax == nopoll_false
            invoke MessageBox,hwnd,chr$("nopoll_conn_is_ok 3 - fails!"),chr$("Problem!"),MB_ICONWARNING
            invoke nopoll_conn_close,conn
            invoke nopoll_ctx_unref,ctx
            mov eax, nopoll_false
            ret           
        .endif
        invoke nopoll_sleep,10000
    .endw
    
    invoke nopoll_msg_get_payload,msg
    .if eax == nopoll_false
            invoke MessageBox,hwnd,chr$("nopoll_msg_get_payload - fails!"),chr$("Problem!"),MB_ICONWARNING
            invoke nopoll_conn_close,conn
            invoke nopoll_ctx_unref,ctx
            mov eax, nopoll_false
            ret        
    .else
            mov esi, eax
            invoke MessageBox,hwnd,esi,chr$("Answer of Server!"),MB_ICONINFORMATION
            jmp @B
    .endif

    invoke MessageBox,hwnd,chr$("Finished!"),chr$("Info!"),MB_ICONINFORMATION
    mov eax, nopoll_true
    ret

Just a test code to see whether and what I get from server / payload message.In this case only one time PING and after a while the connection is no more OK 3 and thats all so far.Has anyone some clue how the exchange should be?

greetz

Share this post


Link to post
Share on other sites
evlncrn8

sounds like the heartbeat in irc.. the ping pong.. basically you'll have to handle normal messages and 'special' messages (like not replying to the ping will most likely result in a disconnection from the server within a reasonably short time period), all of this should be in the respective rfc documentation for the protocol though

https://tools.ietf.org/html/rfc6455#section-1.3

page 27 or so is where the fun begins, and page 36 or so is the ping / pong stuff, basically u have to respond to the ping with the pong and the 'extra data' the ping sent you.. this is essentially the heartbeat / keep alive...

 

  • Like 1

Share this post


Link to post
Share on other sites
LCF-AT

Hi,

I did read that rfc about websockets already but its of course not easy to understand (as always I know).I just only get that one PING as response what I also get if I call the site normaly.Below 2 pics of Opera at websocket traffic starting with first one.Green is sending and red receiving.The PING comes later not at first..

2018-08-22_013835.png.87f0cf6726ca5d3d6ba447e24ddbe2c0.png

2018-08-22_013924.png.12ccfca318456ad09f9f53e10d712128.png

I also tried to send that first string MVN LOAD3 #vl-charliefreak but I also get a while nothing and then just PING.Other datas are not comming in.

@  Teddy

How many times you wanna send that manual link? :) Its not much getting better to find a propper solution.

greetz

Share this post


Link to post
Share on other sites
LCF-AT

Hi again,

I still dont  get it work yet.Now I tried to use any other websocket address and found something here where you can test in browser...

https://www.websocket.org/echo.html

...I tried to use this websocket address with nopoll functions to send / receive something but it fails already when I check whether the connection is OK or Ready (nopoll_conn_is_ok).No idea why this now.The websocket address I get is this..."wss://echo.websocket.org/?encoding=text" using secure socket port 443.

    invoke nopoll_ctx_new
    mov ctx, eax
    invoke nopoll_conn_opts_new
    mov opts, eax
    invoke nopoll_conn_opts_ssl_peer_verify,opts,nopoll_false
    invoke nopoll_conn_tls_new,ctx,opts,chr$("echo.websocket.org"),chr$("443"),0,chr$('/?encoding=text'),0,chr$("https://www.websocket.org")
    mov conn, eax
    invoke nopoll_conn_is_ok,conn
    .if eax == nopoll_false
        invoke MessageBox,hwnd,chr$("nopoll_conn_is_ok 1 - fails!"),chr$("Problem!"),MB_ICONWARNING
        invoke nopoll_conn_close,conn
        invoke nopoll_ctx_unref,ctx
        mov eax, nopoll_false
        ret    
    .endif

    invoke nopoll_conn_is_tls_on,conn
    .if eax == nopoll_false
        invoke MessageBox,hwnd,chr$("nopoll_conn_is_tls_on - fails!"),chr$("Problem!"),MB_ICONWARNING
        invoke nopoll_conn_close,conn
        invoke nopoll_ctx_unref,ctx
        mov eax, nopoll_false
        ret          
    .endif

...it fails on nopoll_conn_is_ok function (before the function was successfully).Also if I check manually nopoll_conn_is_tls_on function = failed too.Can anyone see where the problem could be in this case?Would be nice if anyone could see or show what I am still doing wrong if possible.Thanks.

greetz

Share this post


Link to post
Share on other sites
deepzero
Posted (edited)

Something went terribly wrong when you pasted the  "https ://www.websock et.o r g" parameter, it includes several zero-width space Unicode characters.

Insert a clean version - https://www.websocket.org  

and then it works for me.

edit: seems the zero-width problem is on my end ... seems when copying from the browser it inserts invalid Unicode characters. wtf. Fun times...

---

As for the ping-pong, the manual says:

 

Quote


5.5.2. Ping

The Ping frame contains an opcode of 0x9. A Ping frame MAY include "Application data". Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in response, unless it already received a Close frame. It SHOULD respond with Pong frame as soon as is practical. Pong frames are discussed in Section 5.5.3. An endpoint MAY send a Ping frame any time after the connection is established and before the connection is closed. NOTE: A Ping frame may serve either as a keepalive or as a means to verify that the remote endpoint is still responsive.

5.5.3. Pong

The Pong frame contains an opcode of 0xA. Section 5.5.2 details requirements that apply to both Ping and Pong frames. A Pong frame sent in response to a Ping frame must have identical "Application data" as found in the message body of the Ping frame being replied to. If an endpoint receives a Ping frame and has not yet sent Pong frame(s) in response to previous Ping frame(s), the endpoint MAY elect to send a Pong frame for only the most recently processed Ping frame.


A Pong frame MAY be sent unsolicited.  This serves as a
   unidirectional heartbeat.  A response to an unsolicited Pong frame is
   not expected.

 

Have you tried sending back the Pong opcode of 0xA?

Edited by deepzero (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites
LCF-AT

Hi,

the copy / paste issue to get wrong  values is a problem on this forum since a while already.If I copy some code / text from here and paste it into txt file or WinASM then I also see that problem to get spaces or ? sings inside.I removed them.In  my code it looks clean same in the code I did post before.Why its working for you?Did you test same code as I did post or anything else?

Yes I tried also to send a PONG 4 byte string back after I got a PING 4 byte string but thats all.Just get only PING string after few seconds and nothing else will send to me.In browser I see PONG string with 6 bytes maybe it used crlf.

Here I found something of PING issue..if I check the OPCODE after PING I get opcode 1 using nopoll_msg_opcode.

https://github.com/ASPLes/nopoll/issues/5

Till now I just get PING string using that one wss address and for the echo.websocket.org address it fails before already as I did post before.I dont get anything working yet.

greetz

Share this post


Link to post
Share on other sites
deepzero

Dont think that bug is related, and of course I mislead you  -  that ping/pong stuff is ofc supposed to be handled by the library. I am not sure what kind of ping messages you are receiving though, it seems the vagnsoft endpoint has blacklisted my ip .. or at least I cant connect to it. How do you connect to it via browser? I'll look at it again this WE. Good night.

  • Like 1

Share this post


Link to post
Share on other sites
LCF-AT
Posted (edited)

Hi,

I think too that this ping / pong is handled by the library already.I also dont see any ping / pong code in the whole client code example of nopoll.

Maybe the vagnsoft server address isnt used (103 / 104 / 105) that you got not connected etc.If you visit the main page then you can see which is used in webconsole or if you use FF with AddOn Websocket Detector then you can copy the address directly from bar icon if it pop ups if websocket was found.

In browser (https://websocket.org/echo.html) then you see the location field already filled.Press connect and then send any text.In the log window you see what you did send and received = same.So its sending same back.In browser console of Opera / Chrome you see this...

2018-08-24_005911.png.8d34c3ffa156efc45ae1fe74d7874140.png

greetz

Edited by LCF-AT
http to https in link (see edit history)

Share this post


Link to post
Share on other sites
LCF-AT

Hi again,

short info: Yesterday I did post the link to websocket.org with http instead of https.On the picture above you can also see on the ws:// address in location field that I was calling the site via http (didnt seen that).So you can use both,http and https and you see ws:// or wss://.Now I tried it again and this time I did check the websocket address but this time using port 80 for http / ws and used the functions for this and here its working so far.I can connect and connection has status OK and is also ready.Then I did send some text and right after I am using nopoll_conn_get_msg / nopoll_msg_get_payload and I get the same message I did send back.Same as in browser so far.So it means for this site using ws / http protocol = working (hey one success) but using https / wss / port 443 = not working using nopoll functions.In this case I get failed status back checking if connection is OK / Ready.In browser its working with https / wss / port 443 but not with nopoll functions yet.Not sure why this isnt working now.I also tried to use nopoll_conn_opts_set_ssl_protocol function instead with NOPOLL_METHOD_TLSV1_2 but also dont work.I am not sure whether I need to use nopoll_conn_opts_set_ssl_certs function using certificate files but I think normaly not,so I also dont need to use it if I use OpenSSL functions for https sites.

greetz

Share this post


Link to post
Share on other sites
LCF-AT

Hi,

I tried again a little to get it work.Some sites are working and for some its not working.

Strange thing,for example the vaughnlive.tv sites.If I visit the main page then it does connect to websocket as I told before (getting PING messages).Now if I choose any channel there then it starts a new websocket where I get also the chat traffic to see.The websocket address is like this..

chat-ws-1x07.vaughnsoft.net/mvn

....now I tried to connect this address via nopoll (wss) but it dosent work as it did work for the other address sapi-ws-1x03.vaughnsoft.net from main site websocket.

Example:

invoke nopoll_ctx_new
invoke nopoll_conn_opts_new
invoke nopoll_conn_opts_ssl_peer_verify,opts,nopoll_false
invoke nopoll_conn_tls_new,ctx,opts,chr$("chat-ws-1x07.vaughnsoft.net"),chr$("443"),0,chr$("/mvn"),0,0
invoke nopoll_conn_is_ok,conn
invoke nopoll_conn_is_ready,conn ; <--- here it fails
invoke nopoll_conn_is_ok,conn    ; <--- fails too after

invoke nopoll_ctx_new
invoke nopoll_conn_opts_new
invoke nopoll_conn_opts_ssl_peer_verify,opts,nopoll_false
invoke nopoll_conn_tls_new,ctx,opts,chr$("sapi-ws-1x03.vaughnsoft.net"),chr$("443"),0,0,0,0
invoke nopoll_conn_is_ok,conn
invoke nopoll_conn_is_ready,conn ; <--- Success
invoke nopoll_conn_is_ok,conn    ; <--- Success
...rest works

Now I found another websocket site called

https://websocketstest.com

I did test this site too and its also working...

invoke nopoll_ctx_new
invoke nopoll_conn_opts_new
invoke nopoll_conn_opts_ssl_peer_verify,opts,nopoll_false
invoke nopoll_conn_tls_new,ctx,opts,chr$("websocketstest.com"),chr$("443"),0,chr$("/service"),0,0
invoke nopoll_conn_is_ok,conn
invoke nopoll_conn_is_ready,conn ; <--- success
invoke nopoll_conn_is_ok,conn    ; <--- success
...rest success

...just wanna know why it does work for websocket addresses and for others not to get a successfully handshake.The echo.websocket.org sites using 443 port also dosent work as I told before too.Do these sites need some extra header informations or something like that?

greetz

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×