예제 #1
0
        void FirstBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            ReceivedObject obj = (ReceivedObject)e.UserState;
            Bitmap         a   = obj.Image;
            string         IP  = obj.IP;

            if (mainlist.Exists(aa => aa.IP == IP))
            {
                ((MainListObject)mainlist.Find(b => b.IP == IP)).Image = ToBitmapImage(a);
            }
            else
            {
                MainListObject neww = new MainListObject();
                neww.IP    = IP;
                neww.Image = ToBitmapImage(a);
                neww.port  = obj.port + 1;
                mainlist.Add(neww);
            }
        }
예제 #2
0
        public void OpenListener(int Port, string IP)
        {
            Port--;
            TcpListener   Listener = new TcpListener(IPAddress.Any, Port);
            TcpClient     Client   = new TcpClient();
            NetworkStream mainStream;

            Listener.Start();
            Client = Listener.AcceptTcpClient();
            BinaryFormatter binFormatter = new BinaryFormatter();

            while (Client.Connected)
            {
                mainStream = Client.GetStream();
                try
                {
                    Bitmap a = (Bitmap)binFormatter.Deserialize(mainStream);
                    if (a != null)
                    {
                        ReceivedObject neww = new ReceivedObject();
                        neww.Image = a;
                        neww.IP    = IP;
                        neww.port  = Port;
                        FirstBackgroundWorker.ReportProgress(0, neww);
                    }
                }
                catch
                {
                    mainlist.Remove(mainlist.Find(a => a.IP == IP));
                    if (Global.SessionWin != null)
                    {
                        if (Global.SessionWin.Client.IP == IP)
                        {
                            MessageBox.Show("Przerwano połaczenie z: " + IP);
                        }
                    }
                    Thread.CurrentThread.Abort();
                }
            }
        }