static async Task Main(string[] args) { var send = new NetSend(); client = new SocketClient(async_send: send, sync_send: send); client.BinaryInput += Client_BinaryInput; client.Disconnect += Client_Disconnect; while (true) { await connect(); var fiberRw = await client.GetFiberRw(); async Task Run() { while (true) { try { await SendTest(fiberRw); } catch { break; } } }; //var task1 = Task.Factory.StartNew(async () => // { // while (true) // { // try // { // await SendTest(fiberRw); // } // catch // { // break; // } // } // }); //var task2 = Task.Factory.StartNew(async () => //{ // while (true) // { // try // { // await SendTest(fiberRw); // } // catch // { // break; // } // } //}); //var task3 = Task.Factory.StartNew(async () => //{ // while (true) // { // try // { // await SendTest(fiberRw); // } // catch // { // break; // } // } //}); //var task4 = Task.Factory.StartNew(async () => //{ // while (true) // { // try // { // await SendTest(fiberRw); // } // catch // { // break; // } // } //}); await Task.WhenAll(Run(), Run(), Run(), Run()); } }
static public void ErrorHandler(SocketClient client, Exception e) { Console.WriteLine(e.Message); }
private static void DoReceive(SocketClient client, int numBytes) { Console.WriteLine("Parsing message contents..."); Data[] dat = MessageParser.ParseMessage(client.rawBuffer); for (int i = 0; i < dat.Length; i++) { byte type = dat[i].type; ushort infoType = dat[i].infoType; switch (type) { case Data.INT: Console.WriteLine("Received int: " + dat[i].data_int + " of type " + infoType); break; case Data.UINT: Console.WriteLine("Received uint: " + dat[i].data_uint + " of type " + infoType); break; case Data.SHORT: Console.WriteLine("Received short: " + dat[i].data_short + " of type " + infoType); break; case Data.USHORT: Console.WriteLine("Received ushort: " + dat[i].data_ushort + " of type " + infoType); break; case Data.FLOAT: Console.WriteLine("Received float: " + dat[i].data_float + " of type " + infoType); break; case Data.DOUBLE: Console.WriteLine("Received double: " + dat[i].data_double + " of type " + infoType); break; case Data.LONG: Console.WriteLine("Received long: " + dat[i].data_long + " of type " + infoType); break; case Data.ULONG: Console.WriteLine("Received ulong: " + dat[i].data_ulong + " of type " + infoType); break; case Data.BOOL: Console.WriteLine("Received bool: " + dat[i].data_bool + " of type " + infoType); break; case Data.BYTE: Console.WriteLine("Received byte: " + dat[i].data_byte + " of type " + infoType); break; case Data.SBYTE: Console.WriteLine("Received sbyte: " + dat[i].data_sbyte + " of type " + infoType); break; case Data.CHAR: Console.WriteLine("Received char: " + dat[i].data_char + " of type " + infoType); break; case Data.STRING: Console.WriteLine("Received string: " + dat[i].data_string + " of type " + infoType); break; default: //Throw unknown data exception break; } } }
static public void CloseHandler(SocketClient client) { Console.WriteLine("Close Handler"); Console.WriteLine("IP: " + client.ipAddress); }