Exemple #1
0
 private Connector(String endPoint)
 {
     IPAddress ip = IPAddress.Parse(endPoint);
     groupEP = new IPEndPoint(ip, CONNECTIONPORT);
     isConnected = false;
     Task.Factory.StartNew(() =>
     {
         int retryAttempt = 0;
     Attempt:
         try
         {
             Socket = new UdpClient();
             Socket.Connect(groupEP);
             isConnected = true;
             var handler = ConnectSuccess;
             if (handler != null) handler(this, null);
             startReceiveLoop();
             Socket.Close();
         }
         catch
         {
             Thread.Sleep(1010);
             if (retryAttempt < 10)
             {
                 retryAttempt++;
                 goto Attempt;
             }
             else
             {
                 var handler = ErrorThrown;
                 if (handler != null) handler(this, new ConnectorErrorEventArgs("Socket is locked and not released in 10 seconds, it is being blocked."));
             }
         }
         isConnected = false;
         conn = null;
     });
 }
Exemple #2
0
        public PingRequest(FibeClass fibeClass, string[] tagsArr)
        {
            this.ClassRequested = fibeClass;
            client = fibeClass.client;
            Tags = new ObservableCollection<string>(tagsArr);
            RaisePropertyChanged("tagString");
            When = DateTime.Now;
            isTalking = false;
            connector = fibeClass.connector;

            Payload p = client.makePayload();
            p.path = ClassRequested.path.Concat(new String[] {"audio"}).ToArray();
            p.request = "enqueue";
            int timespan = this.timestamp;
            p.addPayload("time", timespan.ToString());
            p.addPayload("tags", tagsArr);
            p.sessionkey = client.SessionKey;
            p.sessionid = client.SessionID;
            Random rnd = new Random();
            p.identity = packetIdentity = rnd.Next(Int32.MaxValue);
            connector.Send(p);
            connector.ReceivedData += waitForPermit;
        }
Exemple #3
0
 public void FlushConnection()
 {
     try {
         if (connector != null) connector.disconnect();
         connector = null;
     } catch {
     }
 }
Exemple #4
0
        public bool ConnectTo(String s)
        {
            FlushConnection();
            try
            {
                IPAddress[] ip = new IPAddress[] { IPAddress.Parse(s) };
                endpoint = s;
            }
            catch
            {
                try
                {
                    IPAddress[] ip = Dns.GetHostAddresses(s);
                    Random r = new Random();
                    endpoint = ip[r.Next(0, ip.Length - 1)].ToString();
                    connector = Connector.makeConnection(endpoint);
                    DateTime t = DateTime.Now;
                    while (connector.isConnected == false)
                    {
                        Thread.Sleep(500);
                        if ((DateTime.Now - t).Seconds > 10) break;
                    }
                    return connector.isConnected;
                }
                catch
                {

                }
                return false;
            }
            connector = Connector.makeConnection(endpoint);
            return true;
        }
Exemple #5
0
 public static Connector makeConnection(String endpoint)
 {
     return conn = new Connector(endpoint);
 }