public TcpMessageClientTest(ClientSettings ClientSettings)
 {
     _ClientSettings   = ClientSettings;
     _TcpMessageClient = new TcpMessageClient(ClientSettings);
     _TcpMessageClient.ServerMessageHandler += OnServerMessage;
     _TcpMessageClient.RegisterMessageHandler(typeof(MsgText), OnTextMessage);
     _TcpMessageClient.RegisterMessageHandler(typeof(MsgError), OnErrorMessage);
 }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        DebugConsole.Log("TcpTest start");
        if (_client == null)
        {
            _client = new TcpMessageClient(_host, _port, _needHB, new MyMessageParser());

            _client.Register(1, FooResponseHandler);
            _client.Register(-1, CloseHandler);

            TryConnect();
        }
    }
Exemplo n.º 3
0
 public static void Start()
 {
     var client = new TcpMessageClient("localhost", 12354);
     client.On("test", async (c, m) => {
       Console.WriteLine("client received message: {0}", m);
       Task.Factory.StartNew(async () => {
     while (true) {
       await client.SendAsync(null, "tick", null);
       await Task.Delay(1000);
     }
       });
       return true;
     });
     client.Start();
 }
        public void Disconnect()
        {
            IsConnected = false;

            TcpMessageClient client;

            lock (this.interlock)
            {
                client      = this.client;
                this.client = null;
            }

            if (client == null)
            {
                return;
            }

            client.DropPipe();
            client.Dispose();
        }
        public void GetUserOptionsSync(ILoginInfo loginInfo, Action <ConnectionSystemState, UserOptions> callback)
        {
            try
            {
                Hostname = loginInfo.Hostname;
                Port     = loginInfo.Port;
                Security = loginInfo.Security;

                // create tcp client
                TcpMessageClient client = new TcpMessageClient(Hostname, Port, Security);

                client.StartReceiving();

                UserOptionsRequest request = new UserOptionsRequest(callback);

                client.ReceivePipe = request;

                client.SendPipe.PostMessage(new Message(Symbol.Intern("UserOptions")).Append(Symbol.Intern("GetGroups"), Symbol.Intern("GetGroupIDs")));
            }
            catch (Exception) // may be IO, may be other
            {
                callback(ConnectionSystemState.Unknown, new UserOptions());
            }
        }
Exemplo n.º 6
0
        public TerrainClient(String serveraddress, int port)
        {
            myTcpClient = new TcpMessageClient(serveraddress, port);

            myTcpClient.receivedEvent += new TcpMessageClient.EventCallback(handleMessage);
        }
        //HostName, Username, password, PortNumber, SelectedGroup)
        public bool Connect(string hostname, string username, string password, ushort portNumber, Symbol groupID, string locale)
        {
            IsConnected = false;


            var logonInfo = new StubLoginInfo
            {
                Hostname = hostname,
                //Hostname = User specified hostname,
                Port = portNumber,
                //Port = 1338,
                Security = TransportSecurity.Insecure,
                //Security = 0,
                UserName = username,
                GroupID  = groupID,
                Locale   = locale
                           //GroupID = Symbol.Intern("Pdmusers")
            };

            LoginInfo = logonInfo;

            var client = new TcpMessageClient(
                hostname,
                portNumber,
                TransportSecurity.Insecure);

            lock (this.interlock)
                this.client = client;

            // insert logging between stub and client
            BidiSharedPipe shared = new BidiSharedPipe();

            if (this.LogMessage != null)
            {
                shared.Send.MessageReceived += new LogPipe("sent", this.LogMessage).PostMessage;
                shared.Recv.MessageReceived += new LogPipe("recv", this.LogMessage).PostMessage;
            }

            shared.Send.MessageReceived += client.SendPipe.PostMessage;

            client.ReceivePipe = shared.Recv;

            shared.Recv.PipeDropped += OnConnectionDropped;

            client.StartReceiving();

            // create a stub system interface and get back some IDL
            Message idl;

            var connectSettings = new ConnectSettings
            {
                Client          = shared,
                Secret          = password,
                UiClientVersion = appVersion,
                ClientType      = "SSEClientUi"
            };

            var systemInterface = SystemInterfaceStub.Connect(connectSettings, logonInfo, out idl);

            lock (this.interlock)
            {
                idl.Extract(Symbol.Intern("GroupID"), out this.groupID);
                this.systemInterface = systemInterface;
                _idl        = idl;
                IsConnected = true;
            }

            sessionId_   = client.SessionId;
            remIPAddress = connectSettings.remIPAddress; // this session as seen by remote
            remPort      = connectSettings.remPort;      // this session as seen by remote
            return(IsConnected);
        }