예제 #1
0
 void Connect()
 {
     user            = new AdHocDesktop_TcpClient(connectTextBox.Text, AdHocDesktop_TcpUtil.DefaultServerPort);
     user.Connected += new EventHandler(user_Connected);
     user.Received  += new AdHocDesktop_TcpReceivedEventHandler(user_Received);
     user.Error     += new AdHocDesktop_TcpErrorEventHandler(user_Error);
     user.Start();
 }
예제 #2
0
        void server_AcceptClient(AdHocDesktop_TcpClient acceptClient)
        {
            AdHocDesktop_AsyncCallback ad = new AdHocDesktop_AsyncCallback(ServerAcceptClientCallback);

            this.BeginInvoke(ad, new object[] { acceptClient });

            acceptClient.Received += new AdHocDesktop_TcpReceivedEventHandler(acceptClient_Received);
            acceptClient.Error    += new AdHocDesktop_TcpErrorEventHandler(acceptClient_Error);
        }
        public AdHocDesktop_StreamingForm(AdHocDesktop_TcpClient user, string src, string title)
        {
            this.user  = user;
            this.src   = src;
            this.title = title;

            InitializeComponent();
            Initialize();

            user.Received += new AdHocDesktop_TcpReceivedEventHandler(user_Received);
            user.Error    += new AdHocDesktop_TcpErrorEventHandler(user_Error);
        }
예제 #4
0
        void SendEndSession(AdHocDesktop_TcpClient client, AdHocDesktop_TcpCommand command)
        {
            List <AdHocDesktop_TcpClient> groups = groupTable[client.Identifier];

            for (int i = 0; i < groups.Count; i++)
            {
                if (!groups[i].IsConnected)
                {
                    groups.RemoveAt(i);
                    i--;
                }
            }
            for (int i = 0; i < groups.Count; i++)
            {
                AdHocDesktop_TcpClient dest = groups[i];
                dest.Send(new AdHocDesktop_TcpObject(command, client.Identifier, dest.Identifier, new byte[1]));
            }
        }
예제 #5
0
        void ServerDisconnectClientCallback(object obj)
        {
            AdHocDesktop_TcpClient client = (AdHocDesktop_TcpClient)obj;

            AppendLog("中斷連線: " + client.Socket.RemoteEndPoint + "(" + server.GetIdentifier(client) + ")");

            if (winceClients.Contains(client.Identifier))
            {
                winceClients.Remove(client.Identifier);
            }
            if (groupTable.ContainsKey(client.Identifier))
            {
                groupTable.Remove(client.Identifier);
            }
            if (clientTable.ContainsKey(client.Identifier))
            {
                clientTable.Remove(client.Identifier);
            }
            SyncPeople();
        }
예제 #6
0
        void SendStreaming(AdHocDesktop_TcpClient client, byte[] buffer, AdHocDesktop_TcpCommand command)
        {
            bandwidthInput += (buffer == null ? 0 : buffer.Length);
            List <AdHocDesktop_TcpClient> groups = groupTable[client.Identifier];

            for (int i = 0; i < groups.Count; i++)
            {
                if (!groups[i].IsConnected)
                {
                    groups.RemoveAt(i);
                    i--;
                }
            }
            for (int i = 0; i < groups.Count; i++)
            {
                AdHocDesktop_TcpClient dest = groups[i];
                if (winceClients.Contains(dest.Identifier))
                {
                    Size size = new Size(240, 180);
                    if (command == AdHocDesktop_TcpCommand.StreamingCamera)
                    {
                        using (Bitmap b = ImageUtil.ByteToBitmap(buffer))
                        {
                            buffer = ImageUtil.ResizeBitmapToJpegByte(b, size);
                        }
                    }
                    else if (command == AdHocDesktop_TcpCommand.StreamingScreen)
                    {
                        using (Bitmap b = ImageUtil.ByteToBitmap(GZipUtil.Decompress(buffer)))
                        {
                            buffer = GZipUtil.Compress(ImageUtil.ResizeBitmapToByte(b, size));
                        }
                    }
                }
                dest.Send(new AdHocDesktop_TcpObject(command, client.Identifier, dest.Identifier, buffer));
                bandwidthOutput += (buffer == null ? 0 : buffer.Length);
            }
        }
 public AdHocDesktop_ProfileStream(AdHocDesktop_TcpClient user, AdHocDesktop_ProfileJoin join)
 {
     this.user = user;
     this.join = join;
 }
예제 #8
0
        void DisconnectClient(AdHocDesktop_TcpClient disconnectClient)
        {
            AdHocDesktop_AsyncCallback ad = new AdHocDesktop_AsyncCallback(ServerDisconnectClientCallback);

            this.BeginInvoke(ad, new object[] { disconnectClient });
        }
예제 #9
0
 void server_DisconnectClient(AdHocDesktop_TcpClient disconnectClient)
 {
     DisconnectClient(disconnectClient);
 }
예제 #10
0
        void ServerAcceptClientCallback(object obj)
        {
            AdHocDesktop_TcpClient client = (AdHocDesktop_TcpClient)obj;

            AppendLog("連線建立在: " + client.Socket.RemoteEndPoint + "(" + server.GetIdentifier(client) + ")");
        }
예제 #11
0
        void acceptClient_Received(object sender, AdHocDesktop_TcpObject obj)
        {
            try
            {
                AdHocDesktop_TcpClient client = (AdHocDesktop_TcpClient)sender;
                object[] objs = obj.Data;
                switch (obj.Command)
                {
                case AdHocDesktop_TcpCommand.RequestIdentifier:
                    string id = (string)objs[0];
                    string pw = (string)objs[1];
                    AdHocDesktop_ProfilePlatform platform = (AdHocDesktop_ProfilePlatform)objs[2];
                    bool result = false;
                    if (id != "" && pw != "")
                    {
                        if (clientTable.ContainsValue(client.Identifier))
                        {
                            result = false;
                        }
                        else
                        {
                            result = true;
                            clientTable[client.Identifier] = id;
                            if (platform == AdHocDesktop_ProfilePlatform.WINCE)
                            {
                                winceClients.Add(client.Identifier);
                            }
                            SyncPeople();
                        }
                    }
                    client.Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.ResponseIdentifier, obj.Src, obj.Dest, client.Identifier, result));
                    break;

                case AdHocDesktop_TcpCommand.RequestPeople:
                    client.Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.ResponsePeople, obj.Src, obj.Dest, people));
                    break;

                case AdHocDesktop_TcpCommand.BeginInvitation:
                    if (!groupTable.ContainsKey(obj.Src))
                    {
                        groupTable[obj.Src] = new List <AdHocDesktop_TcpClient>();
                    }
                    server.GetClient(obj.Dest).Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.BeginInvitation, obj.Src, obj.Dest, clientTable[obj.Src]));
                    break;

                case AdHocDesktop_TcpCommand.EndInvitation:
                    bool accept = (bool)objs[0];
                    if (accept)
                    {
                        AdHocDesktop_TcpClient src = server.GetClient(obj.Src);
                        if (!groupTable[obj.Dest].Contains(src))
                        {
                            groupTable[obj.Dest].Add(src);
                        }
                    }
                    server.GetClient(obj.Dest).Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.EndInvitation, obj.Src, obj.Dest, accept));
                    break;

                case AdHocDesktop_TcpCommand.StreamingScreen:
                case AdHocDesktop_TcpCommand.StreamingCamera:
                case AdHocDesktop_TcpCommand.StreamingAudio:
                    SendStreaming(client, (byte[])objs[0], obj.Command);
                    break;

                case AdHocDesktop_TcpCommand.ProfileCamera:
                case AdHocDesktop_TcpCommand.ProfileScreen:
                    // TODO:
                    break;

                case AdHocDesktop_TcpCommand.EndSession:
                    SendEndSession(client, obj.Command);
                    break;

                case AdHocDesktop_TcpCommand.Interrupt:
                    DisconnectClient(client);
                    break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
예제 #12
0
 public AdHocDesktop_StreamWriter(AdHocDesktop_TcpCommand command, AdHocDesktop_TcpClient user, AdHocDesktop_Profile profile)
 {
     this.command = command;
     this.user    = user;
     this.profile = profile;
 }