public async Task WaitForClient(Action <string> connectionCallback, Action <string> readerCallback)
        {
            var callbackObj = new TcpCallback();

            callbackObj.Listener           = listener;
            callbackObj.ConnectionCallback = connectionCallback;
            callbackObj.ReaderCallback     = readerCallback;

            listener.BeginAcceptTcpClient(AcceptCallback, callbackObj);
        }
        private void AcceptCallback(IAsyncResult ar)
        {
            TcpCallback cb       = (TcpCallback)ar.AsyncState;
            TcpListener listener = cb.Listener;
            TcpClient   client   = listener.EndAcceptTcpClient(ar);

            lock (syncObj)
            {
                Clients.Add(client);
            }
            cb.ConnectionCallback("Client connected");
            WaitForClient(cb.ConnectionCallback, cb.ReaderCallback);
            //Begin reading data
            ReadDataFromClient(client, cb.ReaderCallback);
        }
Beispiel #3
0
        /// <summary>
        /// Обработчик загрузки основной формы
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void MainForm_Load(object sender, EventArgs e)
        {
            TcpCallback callback = new TcpCallback();

            callback.UsersEven    += new EventHandler <CallbackEventArgs>(callback_UsersEven);
            callback.MessageEvent += new EventHandler <CallbackEventArgs>(callback_MessageEvent);

            InstanceContext ctx = new InstanceContext(callback);

            proxy = new TcpServiceClient(ctx);

            user = new UserInfo {
                Name = Guid.NewGuid().ToString().Substring(0, 10)
            };

            proxy.Connect(user);
        }