Skip to content

Instantly share code, notes, and snippets.

@iggyvolz
Created December 22, 2017 19:41
Show Gist options
  • Save iggyvolz/d3178a42d5d71970783321e3a461fa5e to your computer and use it in GitHub Desktop.
Save iggyvolz/d3178a42d5d71970783321e3a461fa5e to your computer and use it in GitHub Desktop.
using Godot;
using System.Text;
public class WebManager : Node2D
{
public const bool secure = true;
StreamPeerTCP tcp;
StreamPeerSSL ssl;
StreamPeer peer;
public override void _Ready()
{
tcp = new StreamPeerTCP();
if (secure)
{
tcp.ConnectToHost("example.com", 443);
ssl = new StreamPeerSSL();
ssl.ConnectToStream(tcp);
peer = ssl;
}
else
{
tcp.ConnectToHost("example.com", 80);
peer = tcp;
}
}
public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseButton mEvent && mEvent.Pressed)
{
GD.Print("Boop!"); // This prints when I click
peer.PutData(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"));
}
}
public override void _Process(float delta)
{
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