Hi
Found this thread
and also this in the wiki
http://wiki.unity3d.com/index.php/Simple_TCP/IP_Server_Code
but need something more bare bones.
Can anyone help me out?
My desktop app has a static IP and will be listening on a predetermined PORT.
Hi
Found this thread
and also this in the wiki
http://wiki.unity3d.com/index.php/Simple_TCP/IP_Server_Code
but need something more bare bones.
Can anyone help me out?
My desktop app has a static IP and will be listening on a predetermined PORT.
I needed a pretty simple listener and did it like this:
using System.Net;
class YourHttpListenerClass
{
private HttpListener listener;
public YourHttpListenerClass(int port)
{
listener = new HttpListener();
listener.Prefixes.Add("http://*:" + port + "/path/to/listen/to/here");
}
public void StartListening()
{
if (!listener.IsListening)
{
listener.Start();
}
listener.BeginGetContext(ListenerCallback, listener);
}
public void ListenerCallback(IAsyncResult result)
{
HttpListener listener = (HttpListener)result.AsyncState;
// Call EndGetContext to complete the asynchronous operation.
HttpListenerContext context = listener.EndGetContext(result);
HttpListenerRequest request = context.Request;
//do your response-handling logic here
listener.BeginGetContext(ListenerCallback, listener);
}
}
And to invoke it so it listens while your game is going
private void someExistingGameMethod()
{
IEnumerator extraThread = StartHttpListenerThread();
StartCoroutine(extraThread);
}
private IEnumerator StartPasswordListener()
{
yourHttpListenerClass.StartListening();
yield return null;
}
Documentation: HttpListener Class (System.Net) | Microsoft Learn
does it solve your need? It’s not specifically tcpip, so if you need that specifically over http perhaps you can give some more detailed info about why this is not sufficient
Thanks, but I don’t believe your example supports Sockets. Ideally I am looking for a solution that supports both web and simple TCP sockets.
Am going to try GitHub - sta/websocket-sharp: A C# implementation of the WebSocket protocol client and server
Very simple socket server using built in .net classes:
Synchronous example of using it:
Older asynchronous example of using it:
(I say older since we use an older version of the framework with unity, so this example uses async methodologies that are supported)
Not necessarily simple in easy to use, but simple in that it’s the barebone what you need to get going. Like how a lever is a simple machine.