// using System; // using System.Collections.Generic; // using System.Text; // using System.Threading; // using System.Runtime.InteropServices; // TODO: remove // namespace BCG // { // public class SmartConnectionManagedWrapper // { // public delegate void MessageDelegate(int msgType, byte[] msg); // private Dictionary myServerToDel = new Dictionary(); // public SmartConnectionManagedWrapper () // { // ClientToServerConnectionWrapper.init(); // Thread readThr = new Thread(new ThreadStart(myReceiveData)); // readThr.Start(); // } // public void initConnection(BlutoSubAddress subAddress) // { // ClientToServerConnectionWrapper.initServerConnection(ClientToServerConnectionWrapper.stringToBytes(subAddress.ip), // subAddress.port); // } // public void send(BlutoSubAddress address, byte[] data) // { // byte[] ip = ClientToServerConnectionWrapper.stringToBytes (address.ip); // ClientToServerConnectionWrapper.sendDataToServer(ip, address.port, data, data.Length); // } // public void resgisterDataCallback(BlutoSubAddress address, MessageDelegate del) // { // lock (this) // { // myServerToDel.Add(address.ToString(), del); // } // } // public void unregisterDataCallback(BlutoSubAddress address, MessageDelegate del) // { // lock (this) // { // myServerToDel.Remove(address.ip); // } // } // public string getClientAsSeenByServer(string serverURL) // { // return ""; // } // private unsafe void myReceiveData() // { // while (true) // { // BlutoTCPClientMessage** psClientPackets = null; // int npts = 0; // ///returns as soon as it gets the first element // ClientToServerConnectionWrapper.getServerData(1000, 1, &psClientPackets, out npts); // for (int i = 0; i < npts; i++) // { // string ip = Marshal.PtrToStringAnsi(psClientPackets[i]->ip); // int port = psClientPackets[i]->port; // string serverURL = new BlutoSubAddress(ip, port).ToString(); // byte[] msg = null; // if (psClientPackets[i]->msgType == 1) // { // msg = new byte[psClientPackets[i]->size]; // Marshal.Copy(psClientPackets[i]->msg, msg, 0, msg.Length); // } // MessageDelegate cb = null; // lock (this) // { // myServerToDel.TryGetValue(serverURL, out cb); // } // if (cb != null) // cb(psClientPackets[i]->msgType, msg); // } // } // } // } // }