My program is a simple one, connecting to a Socket.IO server, emitting one message, then waiting for one in response. How can I keep it running to receive the message - it exits as soon as it has connected. This is my first C# program which hasn't been following a tutorial, so it's probably got quite a few bugs.
using System;
using System.Windows.Forms;
using System.Threading.Tasks;
using SocketIOClient;
namespace socketio
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new Form1());]
SocketIO client = new SocketIO("http://localhost:5000", new SocketIOOptions
{
EIO = 4
});
Connect();
async Task Connect()
{
client.ConnectAsync();
MessageBox.Show("Started");
client.OnConnected += async (socketSender, b) =>
{
await client.EmitAsync("data", new
{
deviceName = System.Environment.MachineName
});
};
client.On("popup", response =>
{
var obj = response.GetValue(0);
string title = obj.GetProperty("title").GetString();
string message = obj.GetProperty("message").GetString();
MessageBox.Show(message, title);
});
}
}
}
}