Created
March 19, 2017 13:12
-
-
Save MagnificentPako/2cf5ef3325e1835342c460de0b55d8b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use "net" | |
use "net/ssl" | |
use "files" | |
use "encode/base64" | |
class MyTCPConnectionNotify is TCPConnectionNotify | |
let _out: Env | |
new iso create(out: Env) => | |
_out = out | |
fun ref connected(conn: TCPConnection ref) => | |
_out.out.print("CONNECTED") | |
var sockKey: String = Base64.encode("1234567890abcdef") | |
var handshake: Handshake = Handshake("gateway.discord.gg","/",sockKey) | |
conn.set_nodelay(true) | |
conn.set_keepalive(10) | |
conn.write(handshake.build()) | |
fun ref received(conn: TCPConnection ref, data: Array[U8] iso): Bool => | |
_out.out.print("GOT: " + String.from_array(consume data)) | |
true | |
actor Main | |
new create(env: Env) => | |
var myFrame: Frame = Frame(true, OPTEXT, "data") | |
try | |
var outFile: File = File(FilePath(env.root as AmbientAuth, "out.bin")) | |
outFile.writev(myFrame.build()) | |
outFile.sync() | |
end | |
var sockKey: String = Base64.encode("1234567890abcdef") | |
var handshake: Handshake = Handshake("gateway.discord.gg?v=6&encoding=json","/?v=6&encoding=json",sockKey) | |
env.out.print(handshake.build()) | |
let sslctx: (None | SSLContext) = try | |
recover SSLContext | |
.>set_client_verify(true) | |
.>set_authority(FilePath(env.root as AmbientAuth, "cacert.pem")) | |
end | |
end | |
try | |
let ctx = sslctx as SSLContext | |
let ssl = ctx.client("gateway.discord.gg") | |
TCPConnection(env.root as AmbientAuth, | |
SSLConnection(MyTCPConnectionNotify(env), consume ssl), | |
"gateway.discord.gg", | |
"443") | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment