コード例 #1
0
ファイル: TcpServer.cs プロジェクト: WELL-E/Hurricane
 protected void SetParameters(string[] parameters, TcpConnection connection)
 {
     if (bool.Parse(parameters[0])) connection.RegisterPositionChanged();
     if (bool.Parse(parameters[1])) connection.RegisterPlayStateChanged();
     if (bool.Parse(parameters[2])) connection.RegisterTrackChanged();
     if (bool.Parse(parameters[3])) connection.RegisterVolumeChanged();
 }
コード例 #2
0
ファイル: TcpServer.cs プロジェクト: WELL-E/Hurricane
 protected void ListenerThread()
 {
     while (true)
     {
         TcpClient client;
         try
         {
             client = listener.AcceptTcpClient();
         }
         catch (Exception)
         {
             break;
         }
         TcpConnection connection = new TcpConnection(client, MusicManager);
         string openline = connection.Reader.ReadLine();
         if (string.IsNullOrEmpty(openline)) continue;
         string[] parameters = openline.Split('|');
         if (parameters.Length < 4 || parameters.Length > 4) { connection.WriteLine("Error: Can't read arguments. Please use \"bool|bool|bool|bool\""); connection.Dispose(); break; }
         bool error = false;
         foreach (var item in parameters)
         {
             bool temp;
             if (!bool.TryParse(item, out temp)) { connection.WriteLine("Error: Can't read arguments. Please use \"bool|bool|bool|bool\""); connection.Dispose(); error = true; break; }
         }
         if (error) continue;
         SetParameters(parameters, connection);
         connection.WriteLine("welcome");
         this.Connections.Add(connection);
         Thread t = new Thread(ListenToConnetion) { IsBackground = true };
         t.Start(connection);
     }
 }