public void RemoveUserDead() { try { if (!lstUsers.InvokeRequired) { int i; for (i = 0; i < _listUsr.Count; i++) { User tmp = (User)_listUsr[i]; if (tmp.GetIEPConvVideo() == null && tmp.GetIEPConvAudio() == null) { if (!tmp.GetHearBeat()) { lstUsers.Items.Remove(tmp.GetUser()); _listUsr.Remove(tmp); tmp = null; } else { tmp.SetHearBeat(false); } } } } else { RemoveUserDeadCallback d = new RemoveUserDeadCallback(RemoveUserDead); Invoke(d, new object[] { }); } } catch (Exception) { } }
/// <summary> /// UDP Server Thread for video frames /// </summary> private void UDPThreadVideo() { Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); sock.ReceiveBufferSize = 10000000; sock.ReceiveTimeout = 900; IPEndPoint iep = new IPEndPoint(IPAddress.Any, _iPortVideo); sock.Bind(iep); EndPoint ep = (EndPoint)iep; int iRead; byte[] data = new byte[10000]; IPEndPoint iepConv; System.Text.Encoding enc; enc = System.Text.Encoding.ASCII; while (!_bStopServer) { try { iRead = sock.ReceiveFrom(data, ref ep); if (iRead > 0) { /*int iCnt = data[2]; * iCnt <<= 8; * iCnt |= data[1];*/ //Console.WriteLine("Thread Video:" + iRead.ToString()); switch (data[0]) { case CMD_ECHO: sock.SendTo(data, iRead, SocketFlags.None, ep); Program.MainForm.UpdateBytesRX(iRead); break; case CMD_FRM_VIDEO: User usr = Program.MainForm.GetUserFromIPNoPort(ep.ToString()); iepConv = usr.GetIEPConvVideo(); if (iepConv != null) { //Console.WriteLine(usr.GetUser() + " > Video "); sock.SendTo(data, iRead, SocketFlags.None, iepConv); } else { Console.Write(usr.GetUser() + " NOT BINDED"); } break; case CMD_BIND_USER: data[iRead] = 0; string sTmp = enc.GetString(data, 1, iRead - 1); User usrReceiver = Program.MainForm.GetUser(sTmp); User usrCaller = Program.MainForm.GetUserFromIPNoPort(ep.ToString()); if (usrReceiver != null) { usrCaller.SetIepVideo(ep.ToString()); usrCaller.SetIEPConvVideo(usrReceiver.GetIEPVideo()); String sCal = usrCaller.GetIEPVideo().Address + ":" + usrCaller.GetIEPVideo().Port; String sDst = usrReceiver.GetIEPVideo().Address + ":" + usrReceiver.GetIEPVideo().Port; Program.MainForm.AddLog("VIDEO BINDING curr:" + ep.ToString() + " --" + usrCaller.GetUser() + " " + sCal + "-> " + usrReceiver.GetUser() + " " + sDst, ""); data[1] = ACK; sock.SendTo(data, 2, SocketFlags.None, ep); } else { Program.MainForm.AddLog(usrCaller.GetUser() + " CANNOT VIDEO BIND ", ""); data[1] = NACK; sock.SendTo(data, 2, SocketFlags.None, ep); } break; } } } catch (Exception) { } } sock.Close(); }