Created
December 23, 2017 03:27
-
-
Save iggyvolz/53088998c4b9cbdb525252aa5a025618 to your computer and use it in GitHub Desktop.
StreamPeerSSL Not Working
This file contains hidden or 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
using Godot; | |
using System.Text; | |
public class Main : Node2D | |
{ | |
public const bool secure = true; | |
StreamPeerTCP tcp; | |
StreamPeerSSL ssl; | |
StreamPeer peer; | |
public override void _Ready() | |
{ | |
tcp = new StreamPeerTCP(); | |
if (secure) | |
{ | |
GD.Print(tcp.ConnectToHost("www.example.com", 443)); // Gives 0, OK | |
ssl = new StreamPeerSSL(); | |
GD.Print(ssl.ConnectToStream(tcp, true, "www.example.com")); | |
peer = ssl; | |
} | |
else | |
{ | |
tcp.ConnectToHost("www.example.com", 80); | |
peer = tcp; | |
} | |
} | |
public override void _Input(InputEvent @event) | |
{ | |
if (@event is InputEventMouseButton mEvent && mEvent.Pressed) | |
{ | |
peer.PutData(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")); | |
GD.Print("Boop!"); // This prints when I click | |
} | |
} | |
public override void _Process(float delta) | |
{ | |
if(secure && ssl.GetStatus()!=1) | |
{ | |
GD.Print(ssl.GetStatus()); | |
} | |
if (peer.GetAvailableBytes()>0) | |
{ | |
GD.Print(peer.GetString(peer.GetAvailableBytes())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment