예제 #1
0
파일: SoundProxy.cs 프로젝트: Mixi59/Stump
        private void OnClientConnected(SocketAsyncEventArgs e)
        {
            var client = new SoundClient(e.AcceptSocket);

            m_clients.Add(client);

            var args = new SocketAsyncEventArgs();

            args.Completed += (sender, arg) => OnClientReceived(arg);
            args.SetBuffer(new byte[8192], 0, 8192);
            args.UserToken = client;

            if (!e.AcceptSocket.ReceiveAsync(args))
            {
                OnClientReceived(args);
            }

            var listenArgs = new SocketAsyncEventArgs();

            listenArgs.Completed += (sender, x) => OnClientConnected(x);
            if (!m_clientListener.AcceptAsync(listenArgs))
            {
                OnClientConnected(listenArgs);
            }
        }
예제 #2
0
파일: SoundProxy.cs 프로젝트: Mixi59/Stump
        private void OnRegReceived(SocketAsyncEventArgs e)
        {
            while (true)
            {
                if (e.BytesTransferred == 0 || e.SocketError != SocketError.Success)
                {
                    ((Socket)e.UserToken).Disconnect(false);
                }
                else
                {
                    var message = Encoding.ASCII.GetString(e.Buffer, e.Offset, e.BytesTransferred);

                    Debug.WriteLine("REG : " + message);

                    // example : main_client_is():1366402807812|
                    if (message.Contains("main_client_is():"))
                    {
                        var index = message.IndexOf("main_client_is():") + ("main_client_is():").Length;
                        var idStr = message.Substring(index, message.IndexOf("|", index) - index);

                        var id = long.Parse(idStr);

                        m_mainClient = m_clients.First(x => x.ID == id);
                    }

                    foreach (var soundClient in m_clients)
                    {
                        soundClient.Socket.Send(e.Buffer, e.Offset, e.BytesTransferred, SocketFlags.None);
                    }

                    if (!((Socket)e.UserToken).ReceiveAsync(e))
                    {
                        continue;
                    }
                }
                break;
            }
        }
예제 #3
0
파일: SoundProxy.cs 프로젝트: Mixi59/Stump
 private void RemoveClient(SoundClient client)
 {
     m_clients.Remove(client);
 }