Exemplo n.º 1
0
        public static void AddFrame(StandardFrame frame)
        {
            //  ProcessFrame(frame);

            Monitor.Enter(_bufforLock);
            try
            {
                _frameBuffor.Add(frame);
                Monitor.Pulse(_bufforLock);
            }
            finally
            {
                Monitor.Exit(_bufforLock);
            }
        }
Exemplo n.º 2
0
        private static void ProcessFrame(StandardFrame frame)
        {
            Logger.Log(frame.Type.ToString() + " " + counter++);
            switch (frame.Type)
            {
                case FrameType.CLICK:
                    _command.LeftClick();
                    break;
                case FrameType.MOVE:
                    //_mouseController.Move(ConvertBytes(frame.Argument,0),ConvertBytes(frame.Argument,4));
                    _command.MoveCursor(ConvertBytes(frame.Argument, 0), ConvertBytes(frame.Argument, 4));

                    break;
                case FrameType.SCROLL:
                    _command.Scroll(ConvertBytes(frame.Argument, 0));
                    break;
                case FrameType.MUTE:
                    _command.Mute();
                    break;
                case FrameType.VOLUME_DOWN:
                    _command.VolumeDown();
                    break;
                case FrameType.VOLUME_UP:
                    _command.VolumeUp();
                    break;
                case FrameType.ZOOM:
                    _command.Zoom(ConvertBytes(frame.Argument, 0));
                    break;
                case FrameType.CLOSE:
                    _command.CloseWindow();
                    break;
                case FrameType.SWITCH:
                    _command.Switch(ConvertBytes(frame.Argument, 0));
                    break;
            }
        }
Exemplo n.º 3
0
        private void readCallback(IAsyncResult ar)
        {
            var state = (SocketClient) ar.AsyncState;
            Socket handler = state.WorkSocket;

            int read = 0;
            try
            {
                read = handler.EndReceive(ar);
            }
            catch (SocketException)
            {
                allDone.Set();
                clients--;
                Logger.Log("Zamknieto połączenie");
                MainWindow.ClientsNumber(clients);
                handler.Close();
            }

            // Data was read from the client socket.
            if (read > 0)
            {
                int startIndex = 0;
                if (state.BrokenFrame != null && state.BrokenFrame.Length > 0)
                {
                    var type = (FrameType) (state.BrokenFrame[0]);
                    var tmp = new byte[type.GetSize() - 1];
                    for (int i = 0; i < state.BrokenFrame.Length - 1; i++)
                    {
                        tmp[i] = state.BrokenFrame[i + 1];
                    }
                    for (int i = 0, j = state.BrokenFrame.Length - 1; j < type.GetSize() - 1; i++,j++,startIndex++)
                    {
                        tmp[j] = state.Buffer[i];
                    }

                    state.BrokenFrame = null;
                    FrameInterpreter.AddFrame(new StandardFrame(type, tmp));

                }

                for (int i = startIndex; i < read;)
                {
                    //Logger.Log((string)read.ToString("G"));
                    StandardFrame frame = null;
                    var type = (FrameType) (state.Buffer[i]);
                    if (type.GetSize() - 1 > 0)
                    {
                        if (i + type.GetSize() > read)
                        {
                            var tmp = new byte[read - i];
                            Array.Copy(state.Buffer, i, tmp, 0, read - i);
                            state.BrokenFrame = tmp;
                        }
                        else
                        {
                            var tmp = new byte[type.GetSize() - 1];
                            Array.Copy(state.Buffer, i + 1, tmp, 0, type.GetSize() - 1);
                            frame = new StandardFrame(type, tmp);

                            FrameInterpreter.AddFrame(frame);
                        }
                    }
                    else
                    {
                        frame = new StandardFrame(type, null);
                        FrameInterpreter.AddFrame(frame);
                    }

                    i += type.GetSize();
                }
                //  state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, read));
                handler.BeginReceive(state.Buffer, 0, SocketClient.BufferSize, 0,
                                     readCallback, state);
            }
            else
            {
                Logger.Log("Zamknieto połączenie");

                /* if (state.sb.Length > 1)
                {
                    // All the data has been read from the client;
                    // display it on the console.
                    string content = state.sb.ToString();
                    Console.WriteLine("Read {0} bytes from socket.\n Data : {1}",
                       content.Length, content);
                }*/
                handler.Close();
            }
        }