
Procedure ReceiveFrame(connection, *MsgBuffer) If SendNetworkData(connection, *FrameBuffer, Fieldlength + MsgLength) = Fieldlength + MsgLengthĭbg("Textframe send, Bytes: " + Str(Fieldlength + MsgLength)) Debug Str(PeekA(*FrameBuffer + x)) + " | " + Str(PeekA(*FrameBuffer + x + 1)) + " | " + Str(PeekA(*FrameBuffer + x + 2)) + " | " + Str(PeekA(*FrameBuffer + x + 3)) + " | " + Str(PeekA(*FrameBuffer + x + 4)) PokeA(*FrameBuffer + pos, Mask(3)) : pos + 1ĬopyMemory(*MsgBuffer, *FrameBuffer + pos, MsgLength) PokeA(*FrameBuffer + pos, Mask(2)) : pos + 1 PokeA(*FrameBuffer + pos, Mask(1)) : pos + 1 PokeA(*FrameBuffer + pos, Mask(0)) : pos + 1 PokeA(*Framebuffer + pos, MsgLength) : pos + 1 = 10 Byte PokeA(*Framebuffer + pos, MsgLength > 8) : pos + 1 PokeA(*Framebuffer + pos, MsgLength > 16) : pos + 1 PokeA(*Framebuffer + pos, MsgLength > 24) : pos + 1 We don't support giant packages for now, so first bytes are zero :P PokeA(*Framebuffer + pos, 0) : pos + 1 8 Bytes for payload lenght. PokeA(*Framebuffer + pos, 127 + 128) : pos + 1 127 for 8 extra length bytes and + 128 for Masking PokeA(*FrameBuffer + pos, MsgLength) : pos + 1 Second ByteĮlse It's bigger than 65535, we also use 8 extra bytes If MsgLength = 126 And MsgLength = 126 And MsgLength > 8)) : pos + 1 First Byte PokeS(*MsgBuffer, message.s, MsgLength, #PB_UTF8|#PB_String_NoZero)ĭbg("Messagelength to send: " + Str(MsgLength)) MsgLength.l = StringByteLength(message.s, #PB_UTF8) Procedure SendTextFrame(connection, message.s) PokeA(*Buffer + i, PeekA(*Buffer + i) ! Mask(i % 4)) Procedure ApplyMasking(Array Mask.a(1), *Buffer) If FindString(Answer.s, "HTTP/1.1 101") And FindString(Answer.s, "CONNECTION: UPGRADE") And FindString(Answer.s, "UPGRADE: WEBSOCKET") Size = ReceiveNetworkData(connection, *Buffer, 65536)Īnswer.s = Answer.s + PeekS(*Buffer, Size, #PB_UTF8) SendNetworkString(Connection, Request.s, #PB_UTF8) "User-Agent: CustomWebsocketClient"+ #CRLF$ + #CRLF$ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ=" + #CRLF$ + Procedure Handshake(Connection, Servername.s, Path.s) If Handshake(Connection, Servername.s, Path.s) Configure the proxy with SetSSLProxy().")Ĭonnection = OpenNetworkConnection(Servername.s, Port.l, #PB_Network_TCP, 1000) If Protokol.s = "wss" If we connect with encryption (https)Ĭonnection = OpenNetworkConnection(Proxy_Server.s, Proxy_Port.l, #PB_Network_TCP, 1000)ĭbg("We need an SSL-Proxy like stunnel for encryption. Port.l = Val(GetURLPart(URL.s, #PB_URL_Port)) Servername.s = GetURLPart(URL.s, #PB_URL_Site) Protokol.s = GetURLPart(URL.s, #PB_URL_Protocol) Procedure SetSSLProxy(ProxyServer.s = "", ProxyPort.l = 8182) TODO: Support to send receive bigger framesĭeclare Handshake(Connection, Servername.s, Path.s)ĭeclare ApplyMasking(Array Mask.a(1), *Buffer)ĭebug "WebsocketClient: " + FormatDate("%yyyy-%mm-%dd %hh:%ii:%ss",Date()) + " > " + txt TODO: We should send an closing frame, but server will also just close TODO: We don't support fragmetation right now No joy.Declare SendTextFrame(connection, message.s)ĭeclare ReceiveFrame(connection, *MsgBuffer)ĭeclare SetSSLProxy(ProxyServer.s = "", ProxyPort.l = 8182) It displayed the wrong oversized window and debug reported the same 3840x2160 with x 1 and y 1 res. I ran three other tabs first then ran it. Then I exited out and restarted purebasic. Ok, I ran it and it displayed the correct resolution and debug reported 3840x2160 res x 1 and res y 1. MessageRequester("Error", "Can't open windowed!", 0) MessageRequester("Error", "Can't open windowed screen!", 0) Res = OpenWindowedScreen(WindowID(0),0,0,DW,DH,#autoscale,0,0)ĬreateSprite(0, 50, 50) Create an empty sprite, will be whole blackĬlearScreen(RGB(0, 0, 200)) A blue backgroundĭisplaySprite(0, 10, 10) Display our black box at the left-top cornerĭisplaySprite(0, W-60, 10) Display our black box at the right-top cornerĭrawText((W>1)-(TextWidth(out)>1),100,out,RGB(0,255,0),RGB(0,0,255)) Res = OpenWindowedScreen(WindowID(0),0,0,W,H,#autoscale,0,0) If OpenWindow(0,0,0,W,H,"Windowed screen test ",#FLAGS)

MessageRequester("Error", "Can't open screen & sprite environment!", 0)
