Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();

            IPAddress serverIP = IPAddress.Parse(serverIPStr);

            IPEndPoint ipEndPoint = new IPEndPoint(serverIP, serverPort);

            clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //connect the server
            try
            {
                clientSocket.Connect(ipEndPoint);
                Console.WriteLine("Socket connected to {0}",
                        clientSocket.RemoteEndPoint.ToString());
            }
            catch (ArgumentNullException ane)
            {
                Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
            }
            catch (SocketException se)
            {
                Console.WriteLine("SocketException : {0}", se.ToString());
            }

            StateObject state = new StateObject();
            state.workSocket = clientSocket;

#if !SERVER_SIDE
            this.configWindow = new Configuration();
            this.configWindow.config.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(config_PropertyChanged);

            this.configWindow.Show();

            pg = new PatternGenerator(this);
            pg.AddToParent(_my_canvas);
#else
            lData = new LogData();
            stopwatch = new Stopwatch();
#endif

#if SERVER_SIDE
            mcServer = new MutualCommunication("192.168.21.147", 12347);
            mcServer.ServerListen();
            mcServer.RaiseMsgRcvEvent += new MutualCommunication.MessageReceivedEventHandler(mcServer_RaiseMsgRcvEvent);
#else
            mcClient = new MutualCommunication("192.168.21.147", 12347);
            mcClient.ClientConnect();
            mcClient.RaiseMsgRcvEvent += new MutualCommunication.MessageReceivedEventHandler(mcClient_RaiseMsgRcvEvent);

#endif

            //initialize the visualization (null at the beginning) and the targets
            this.visualization = null;
            targets = new Targets();
            // Receive the response from the remote device.
            clientSocket.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);
            //Console.WriteLine("Echoed test = {0}",
            //    Encoding.ASCII.GetString(bytes, 0, bytesRec));
            // this._json_text.Text = Encoding.ASCII.GetString(bytesReceived, 0, bytesRec);

            //a timer to see how many pakages are received per sec
            this.tempTimer = new Timer(1000);
            this.tempTimer.Elapsed += new ElapsedEventHandler(tempTimer_Elapsed);
            this.tempTimer.Enabled = false;

#if !SERVER_SIDE
            dis = new Distractor();
#endif

            // Release the socket.
            if (Keyboard.GetKeyStates(Key.Escape) == KeyStates.Down)
            {
                clientSocket.Shutdown(SocketShutdown.Both);
                clientSocket.Close();
            }
        }
Esempio n. 2
0
        void config_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
                case "visualization":
                    if (this.visualization != null)
                    {
                        this.visualization.StopAnimation();
                        this.visualization.DetachFromParent();
                    }
                    switch (this.configWindow.config.Vis)
                    {
                        case ConfigStatus.VisSts.Dot:

                            this.visualization = new DotVis(this._my_canvas);
                            this.visualization.AddToParent(this._my_canvas);
                            break;
                        case ConfigStatus.VisSts.Ripple:
                            this.visualization = new RippleVis(this._my_canvas);
                            this.visualization.AddToParent(this._my_canvas);
                            this.visualization.StartAnimation();
                            break;
                        default:
                            this.visualization = null;
                            break;
                    }
                    break;
                case "background":
                    pg.showImage(this.configWindow.config.Background);
                    break;
                default:
                    break;
            }
        }