private static byte[] sendMessage(byte[] messageBytes) { const int bytesize = 1024 * 1024; try // Try connecting and send the message bytes { System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient(127.0 .0 .1, 8001); // Create a new connection NetworkStream stream = client.GetStream(); stream.Write(messageBytes, 0, messageBytes.Length); // Write the bytes Console.WriteLine(== == == == == == == == == == == == == == == ==); Console.WriteLine( = Connected to the server = ); Console.WriteLine(== == == == == == == == == == == == == == == ==); Console.WriteLine(Waiting for response...); messageBytes = new byte[bytesize]; // Clear the message // Receive the stream of bytes stream.Read(messageBytes, 0, messageBytes.Length); // Clean up stream.Dispose(); client.Close(); } catch (Exception e) // Catch exceptions { Console.WriteLine(e.Message); } return(messageBytes); // Return response }
This class is primarily designed for a "single producer, single consumer" layout. So Jobs are only added to the queue from the main thread (the thread that calls Update on the queue). The class supports adding jobs from other threads by using "AddJobFromOtherThreads" instead of "AddJob". This will store the job in an additional "locked" queue which then will be copied into the actual job queue.
- virtual void OnFinished() - This is a callback which will be invoked from the main thread(the thread that
target of the link is applicable to the current platform (the host environment)
Usage The class is designed for use in Unity's GUI coordinates. With this coordinate system, the origin is at the top left of the screen, x values increase from left to right, and y values increase as you go DOWN the screen. If you do some careful coordinate transformations, you probably should be able to use the code with an arbitrary coordinate system, but this was not the usage I designed it for, so beware.