This is a creation in Article, where the information may have evolved or changed.
Unity section:
Create a new script and hang it under a random object. The code is as follows:
using UnityEngine;using System.Collections;using System.Text;public class TestScript : MonoBehaviour{ public string url = "http://127.0.0.1:8000/test";public string test_string;// Use this for initializationIEnumerator Start (){ WWW www = new WWW (url); yield return www; print (www.bytes); test_string = System.Text.Encoding.UTF8.GetString (www.bytes); print (test_string);}// Update is called once per framevoid Update (){}}
Go section
<!--lang:cpp-->package mainimport ("FMT" "Html/template" "Net/http") func main () {FMT. Printf ("Server start\n") http. Handle ("/img/", http. Fileserver (http. Dir ("TPL"))) HTTP. Handlefunc ("/", Notfoundhandler) http. Handlefunc ("/index", Indexhandler) http. Handlefunc ("/test", Testhandler) http. Listenandserve (": 8000", nil) fmt. Printf ("Server closed\n")}func Notfoundhandler (w http. Responsewriter, R *http. Request) {if r.url. Path = = "/" {http. Redirect (W, R, "/index", http. Statusfound)} t, E: = template. Parsefiles ("tpl/html/404.html") if E! = nil {errorlog (e)} t.execute (W, nil)}func Testhandler (w http. Responsewriter, R *http. Request) {//below for Test FMT. Println ("Postform", r.postform) Test: = R.postform.get ("Test") fmt. Println ("Test string:", test)//upside for test returnstring: = "return test value!" Returnbytes: = []byte (returnstring) I, E: = W.write (returnbytes) fmt. Println ("I,e:", I, E)}func IndexhandLer (w http. Responsewriter, R *http. Request) {T, E: = template. Parsefiles ("tpl/html/index.html") if E! = nil {errorlog (e)} t.execute (W, nil)}func errorlog (e error) {FM T.println (E)}