Example #1
0
        private static Device <Sensors> ConfigureTcpNetworkDeviceAP()
        {
            //first connect over serial to the device
            Console.Clear();
            Console.WriteLine("Setting up prop over usb...");
            Console.WriteLine("Enter the WiFi network SSID: ");
            string ssid = Console.ReadLine();

            Console.WriteLine("Enter the Wifi network Password: "******"ArduinoConfig");
            string ipAddress    = "";
            bool   isDoneConfig = false;
            MessageRecievedHandler <Config> messageHandler = (device, message) =>
            {
                if (message.Status == "Done")
                {
                    ipAddress    = message.DeviceIp;
                    isDoneConfig = true;
                }
            };

            serialConfig.Recieved += messageHandler;
            serialConfig.Connect();
            serialConfig.Send(new Config()
            {
                WifiCredentials = new WifiCredentials()
                {
                    SSID     = ssid,
                    Password = pass
                }
            });
            while (!isDoneConfig)
            {
                //just keep running...
            }
            serialConfig.Recieved -= messageHandler;
            serialConfig.Disconnect();
            serialConfig.Dispose();
            ConfigurationManager.AppSettings["DeviceIp"] = ipAddress;
            Console.WriteLine("Now recieving data, you may now disconnect the device");
            return(new TCPNetworkDevice <Sensors>(ipAddress, 53005, "ArduinoProp"));;
        }
Example #2
0
        public PeerConnection(IPEndPoint ep, MessageRecievedHandler handler, int piecesCount, byte[] expectedInfoHash,
                              DownloadingFile.TimeOutCallBack TimeOut)
        {
            connectionState  = 0;
            connectionState  = CONNSTATES.AM_CHOKING | CONNSTATES.PEER_CHOKING;
            connectionClient = new TcpClient();
            peersPieces      = new BitArray(piecesCount);
            bitfieldSent     = false;
            endPoint         = ep;
            MsgRecieved      = handler;
            wrongCount       = 0;
            maxPendingOutgoingRequestsCount = 5;

            IncomingRequests      = new LinkedList <Tuple <int, int> >();
            infoHash              = expectedInfoHash;
            outgoingRequests      = new Tuple <int, int> [maxPendingOutgoingRequestsCount];
            outgoingRequestsCount = 0;
            TimeOutCallback       = TimeOut;
        }
Example #3
0
        /*
         * No need to add documentation here
         * User will only handle the delagates and events
         * */

        public static void OnMessageRecievedEventHandler(FMessage mess)
        {
            MessageRecievedHandler h = MessageRecievedEvent;

            if (h == null)
            {
                return;
            }
            foreach (Delegate tmpSingleCast in h.GetInvocationList())
            {
                ISynchronizeInvoke tmpSyncInvoke = tmpSingleCast.Target as ISynchronizeInvoke;
                if (tmpSyncInvoke != null && tmpSyncInvoke.InvokeRequired)
                {
                    tmpSyncInvoke.Invoke(tmpSingleCast, new object[] { mess });
                    continue;
                }
                h.Invoke(mess);
            }
        }
Example #4
0
        public Client(TcpClient socket, MessageRecievedHandler mHandler, ConnectionClosedHandler cHandler)
        {
            this.socket   = socket;
            this.mHandler = mHandler;
            this.cHandler = cHandler;

            clientIn  = new StreamReader(socket.GetStream());
            clientOut = new StreamWriter(socket.GetStream());

            clientOut.AutoFlush = true;

            //exchange port numbers with remote hosts;
            clientOut.WriteLine(Program.myPort);
            RemotePort = int.Parse(clientIn.ReadLine());

            Console.WriteLine("Verbonden: " + Program.ConvertToPort(RemotePort));

            //start the message handling thread
            Thread t = new Thread(ReadMessages);

            t.Start();
        }