Example #1
0
 /**
  * Poll <index> //polls the specified index from tickletQueue
  * || Poll dgaf //polls the next element (don't care which one) from tickletQueue
  * */
 private void handleMessagePoll(String data, Socket clientSocket)
 {
     lock (tickletQueue)
     {
         if (tickletQueue.Count() > 0)
         {
             if ("dgaf".Equals(data))
             {
                 Ticklet tick          = tickletQueue.Values.ElementAt(0);
                 int     tickID        = tickletQueue.Keys.ElementAt(0);
                 String  messageString = tick.getID() + " " + tick.getConnectionString();
                 tickletQueue.Remove(tickID);
                 sendMessageTo(new Message("T", messageString), clientSocket);
             }
             else
             {
                 int  index;
                 bool parsed = int.TryParse(data, out index);
                 Console.WriteLine(index + " " + parsed);
                 if (parsed)
                 {
                     Ticklet tick;
                     bool    hasTick = tickletQueue.TryGetValue(index, out tick);
                     if (hasTick)
                     {
                         int    id        = tick.getID();
                         String conString = tick.getConnectionString();
                         Console.WriteLine("polled ID# " + id + " from queue");
                         String messageString = id + " " + conString;
                         tickletQueue.Remove(index);
                         sendMessageTo(new Message("T", messageString), clientSocket);
                     }
                     else
                     {
                         sendMessageTo(new Message("PollFail", ":("), clientSocket);
                     }
                 }
                 else
                 {
                     sendMessageTo(new Message("PollFail", ":("), clientSocket);
                 }
             }
         }
         else
         {
             sendMessageTo(new Message("PollFail", ":("), clientSocket);
         }
     }
 }
Example #2
0
 /**
  * Ticklet <ConnectionString>
  * */
 private void handleMessageTicklet(String data, Socket clientSocket)
 {
     //update ticklet queue with new entry
     lock (tickletQueue)
     {
         int id = entities.SocketToID(clientSocket);
         if (id == null)
         {
             throw new Exception("A client connected without recieving an ID!");
         }
         Ticklet newTick = new Ticklet(id, data);
         tickletQueue.Add(id, newTick); //TODO change this to also include additional information about the client
     }
     Console.WriteLine("updated ticklet queue (in theory)");
 }