Cramming a Terraria server into a free project container

Project URL:!/honorable-great-position?

How to connect

  1. Download a copy of and run that. Even if you’re on Windows, you’re here on Glitch, which means you probably have Git, which you probably installed the Git for Windows distribution, which ships with Perl. You won’t see any output at this point.
  2. Connect to localhost:7777 in Terraria.
  3. The script that’s running should output HTTP/1.1 101 Switching Protocols. But sometimes it takes multiple tries. Rerun the script if you need to try again, because it exits each time.
  4. The game should connect after that.

Technical info

The connection

Glitch’s router lets you upgrade an HTTP connection and then send and receive anything. Terraria multiplayer runs on TCP. I think. I’ve found about a dozen port forwarding guides that say to forward both TCP and UDP and one obscure Reddit comment that it only uses TCP.

The client script

It just sends the HTTP upgrade request, chops off the response header, and pipes stuff from a connection on the normal Terraria port.

It’s written in Perl because that’s all I had on my Windows computer.

It only accepts a single connection and exits after the connection closes, so re-run it if you have to try multiple times. It was hard enough getting this much working in Perl.

Feel free to write up a ~5 line solution in Node.js.

HTTP 502 errors

I haven’t found out why this happens yet.

Resource limits

Even on a “Small” size world, it takes >600 MB RAM. You could try it if you boosted, I guess. But I found a user-created map that’s even smaller than that It comes in at ~490 MB of RAM. We’re cutting it close.

This map was created in the 1.2 era though, so it’s probably missing stuff. If anyone’s handy at Terraria modding, could I have you create a new tiny map for me? It looks like TerraCustom is able to make a smaller-than-small map, but I ran into some weird stuff where it’s looking for version but I only have version \:

An attempt at gracefulness

It’s supposed to save and exit when the container is going down for sleep.


Amazing…thanks for the concept I’m going to try to use a script for minecraft servers which might have more optimization plugins