Esempio n. 1
0
        public void runCBListenerFaster()
        {
            this.cbListener = new Thread(() =>
            {
                try
                {
                    Thread.CurrentThread.IsBackground = true;



                    while (true)
                    {
                        //ho spostato qui queste tre righe per evitare il prob che ogni volta va tutto a puttane
                        Console.Write("Waiting for ClipBoard connection... ");
                        TcpClient acceptedClient = this.cbSocketServer.AcceptTcpClient();
                        Console.WriteLine("Clipboard is Connected!");

                        Thread.Sleep(100);
                        try
                        {
                            Console.WriteLine("Aspettando un messaggio dalla clipboard");
                            NetworkStream stream = acceptedClient.GetStream();
                            byte[] buffer        = receiveAllData(stream);

                            Object received = AmbrUtils.ByteArrayToObject(buffer);
                            Console.WriteLine("FINE RICEZIONE\t Tipo: " + received.GetType() + " Dimensione : " + buffer.Length + " bytes");
                            SetClipBoard(received);
                            Console.WriteLine("CBLISTENER : clipboard settata");
                        }
                        catch (IndexOutOfRangeException cbex)
                        {
                            //eccezione generata quando chiudo il client dalla clipboard
                            //bool b = this.isConnected;
                            Console.WriteLine("Index Out Of Range  generata in cb: [{0}]", cbex.Message);
                            //this.isConnected = false;
                            //closeOnException();
                            return;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("ECCEZIONE GENERATA IN RICEZIONE CB : [{0}]", ex.Message);
                            return;
                            //closeOnException();
                            //return;
                            // restartServer();
                        }
                    }
                }

                catch (Exception e)
                {
                    Console.WriteLine("Eccezione generica in cblistener " + e.Message);
                    return;
                }
            });
            this.cbListener.Start();
        }
Esempio n. 2
0
        internal bool authenticateWithPassword()
        {
            byte[] b = AmbrUtils.ObjectToByteArray(this.password);
            Console.WriteLine("Mandato password : [" + this.password + "]");

            //UdpSender.Send(b, b.Length);
            server.Client.Send(b, b.Length, 0);

            //byte[] receivedResponse = UdpSender.Receive(ref remoteIPEndPoint);
            byte[] receivedResponse = new byte[AmbrUtils.ObjectToByteArray(new Boolean()).Length];
            server.Client.Receive(receivedResponse);
            Boolean result = (Boolean)AmbrUtils.ByteArrayToObject(receivedResponse);

            return(result);
        }