I have a C# dotnetcore console app running on an AWS instance, and I would like to add in communication between this and my playfab cloudscript.
I can communicate from the C# console to playfab, that was simple just using the playfab nuget package. However I'm having trouble going the other way.
I only ever want to send a few different simple messages, so im not looking for anything too complex. What I have done so far, is I added the following to the start of my console application:
var listener = new HttpListener(); listener.Prefixes.Add("http://+:80/"); listener.Start(); Writer.WriteBuffer("Listening..."); HttpListenerContext context = listener.GetContext(); HttpListenerRequest request = context.Request; // Obtain a response object. HttpListenerResponse response = context.Response; // Construct a response. Writer.WriteBuffer("Context: " + context.ToString()); Writer.WriteBuffer("request: " + request.ToString()); Writer.WriteBuffer("response: " + response.ToString()); string responseString = "<HTML><BODY> Hello world!</BODY></HTML>"; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); // You must close the output stream. output.Close(); listener.Stop();
Writer.WriteBuffer is a wrapper for writing Console.Write essentially, just formats stuff in a much better way for me. I see the "listening..." come up, so great its listening.
Now, I copied an example from playfab and just adapted it very slightly. cloudscript is in js, so here is what I am running from playfab:
var headers ={"X-MyCustomHeader":"Some Value"};var body ={ input: args, userId: currentPlayerId, mode:"foobar"};var url ="http://11.111.111.1/";var content = JSON.stringify(body);var httpMethod ="post";var contentType ="application/json";// The pre-defined http object makes synchronous HTTP requestsvar response = http.request(url, httpMethod, content, contentType, headers);return{ responseContent: response };
11.111.111.1 is where I put the IP address of the AWS instance (I've changed it for obvious reasons).
When running this, I get "httpRequestError": "Timeout". When I check on AWS, I have nothing else printed out other than "Listening...", so it hasn't handled anything yet.
I'm not too sure where the problem lies to be honest.