예제 #1
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //------------------------------------------------------------------------------------------------------------------------

        public void connect(string server, string audiotoken, int Port = 6517, bool SecureYPC = false)
        {
            //start a YPclient
            DebugEx.TraceLog("Connect mic client to mic server");
            this.audiotoken = audiotoken;
            //create protocol
            var proto = new YPChannel.Protocol()
            {
                Version             = 1,
                ProtocolDefinitions = new List <Protocol.MessageTypeGroup>()
                {
                    new Protocol.MessageTypeGroup()
                    {
                        GroupName = Yodiwo.API.MediaStreaming.Audio.ApiGroupName, MessageTypes = Yodiwo.API.MediaStreaming.Audio.ApiMessages
                    }
                },
            };

            //create channel
            yclient = new Yodiwo.YPChannel.Transport.Sockets.Client(proto)
            {
                Name = "AudioMediaClient"
            };
            yclient.OnMessageReceived += clientOnMessageReceived;
            yclient.Connect(server, Port, SecureYPC);
        }
예제 #2
0
        //-------------------------------------------------------------------------------------------------------------------------
        public bool Connect()
        {
            YPChannel.Transport.Sockets.Client _client = null;
            lock (this)
                try
                {
                    //check that is not already connecting/conntected
                    var _tmpypc = ClientChannel;
                    if (_tmpypc != null && _tmpypc.State != YPChannel.ChannelStates.Closed)
                    {
                        return(_tmpypc.State == YPChannel.ChannelStates.Open);
                    }

                    //dispose previous ypchannel
                    if (_tmpypc != null)
                    {
                        try { _tmpypc.Close("Resetting channel"); } catch { }
                        try { _tmpypc.Dispose(); } catch { }
                    }

                    //create ypchannel client
                    _client = new YPChannel.Transport.Sockets.Client(NodeDiscoverManager.Protocol);
                    SetupChannel(_client);

                    //connect
                    DebugEx.TraceLog($"RemoteNode : Connecting to node. (ip:{IPAddress} port:{RemotePort} nodekey:{RemoteNodeKey})");
                    lastConnectionAttempt = DateTime.Now;
                    var conRes = _client.Connect(IPAddress, RemotePort, false);
                    if (conRes)
                    {
                        DebugEx.TraceLog($"RemoteNode : Connected to node. (ip:{IPAddress} port:{RemotePort} nodekey:{RemoteNodeKey})");
                        return(true);
                    }
                    else
                    {
                        try { _client.Close("error(1)"); } catch { }
                        try { _client.Dispose(); } catch { }
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    DebugEx.TraceError(ex, "Error while connecting to discovered node");

                    //close channel
                    try { _client?.Close("erro(2)r"); } catch { }
                    try { _client?.Dispose(); } catch { }

                    //switch state to reconnection sleep
                    lastConnectionAttempt = DateTime.Now;
                    return(false);
                }
        }