private void OnConnectCallback(IAsyncResult ar) { Socket sock = (Socket)ar.AsyncState; if (sock == null) return; IPEndPoint ep = null; try { sock.EndConnect(ar); ep = sock.RemoteEndPoint as IPEndPoint; _TCP = new ATCPConnector(sock, Uid64.CreateNewSync().Data, NetHelper.READ_BUFFER_BIG); _TCP.DisconnectEvent += OnDisconnectEventHandler; _TCP.ReceiveAction += OnReceveDataHandler; _TCP.ReceiveComAction += OnReceiveCommandHandler; } catch (SocketException ex){ sock.Close(); sock = null; NetLogger.Log(ex); return; } _isActive = true; if (ep != null) { NetLogger.Log("Connected to " + sock.RemoteEndPoint); } ConnectEvent?.Invoke(this, _TCP); }
private void NCCreateNewPictureBox(IConnector connection, ArgNewPictureBox arg) { long clientFakePBID = arg.PictureBoxID; long realEditablePBID = Uid64.CreateNew().Data; arg.PictureBoxID = realEditablePBID; lock (_npbSync) { _newPB.Enqueue(arg.PictureBoxID, arg); _clientServerPictureBoxID[clientFakePBID] = realEditablePBID; } lock (_astSync) { _argsSendToAllClients.Add(arg); } NetLogger.Log("CreatePB from: " + clientFakePBID + " to " + realEditablePBID); }
private void NCAutorizeNewClient(IConnector connector, ArgComAutorize arg) { if (arg == null || connector == null) { return; } ATCPConnector atcpcon = connector as ATCPConnector; if (atcpcon == null) { return; } if (!string.IsNullOrEmpty(arg.Login) && arg.Password == "Password") { _autorizator.RemoveConnector(connector.UniqueID); ArgUniqueID argClientID = new ArgUniqueID(NComSendClientID.uniqueID); argClientID.UniqueID = Uid64.CreateNewSync().Data; TeamPainterTCPClient client = new TeamPainterTCPClient(atcpcon, argClientID.UniqueID, arg.Login); bool added = _worker.AddClient(client); if (!added) { client.Disconnect(); return; } lvClients.Invoke((MethodInvoker) delegate { ListViewItem lvi = lvClients.Items[client.Connector.UniqueID.ToString()]; if (lvi != null) { lvi.Name = client.UniqueID.ToString(); lvi.SubItems[0].Text = client.UniqueID.ToString(); lvi.SubItems[1].Text = arg.Login; lvi.BackColor = Color.WhiteSmoke; lvi.ForeColor = Color.Black; lvClients.Invalidate(); } }); connector.SendCommand(argClientID); } }
private PictureBoxObj CreateNewPictureBox(Image img, Point location) { //Create facepictureBox PictureBoxObj pic = new PictureBoxObj(_netClient.ClientID, Uid64.CreateNew().Data, PictureBoxStatus.IsMovable); if (img != null) { pic.Image = img; pic.Width = img.Width; pic.Height = img.Height; } SubscribeControl(pic); pic.BorderStyle = BorderStyle.FixedSingle; pic.BringToFront(); pic.Parent = _canvas.FrontPicture; pic.Location = location; //Send it to serever SendComNewPictureBox(pic); return(pic); }
public TPHostAutorizator(int maxCount) { _maxCount = maxCount; _listener = new ATCPListenModule(Uid64.CreateNew().Data, NetHelper.READ_BUFFER_BIG); _listener.NewConnectionEvent += OnNewConnectionHandler; }