Exemplo n.º 1
0
        public Client Start(SdjMainViewModel main)
        {
            SdjMainViewModel           = main;
            Receiver                   = new ClientReceiver(main);
            _debug                     = new Debug("Connection");
            Config                     = ClientConfig.LoadConfig();
            ClientInfo.Instance.Client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(Config.Ip, Config.Port));
            ClientInfo.Instance.Client.MessageReceived += Client_MessageReceived;
            ClientInfo.Instance.Client.Disconnected    += Client_Disconnected;
            ClientInfo.Instance.ReplyMessenger          = new RequestReplyMessenger <IScsClient>(ClientInfo.Instance.Client);
            ClientInfo.Instance.ReplyMessenger.Start();

            ClientInfo.Instance.Client.ConnectTimeout = 400;

            while (ClientInfo.Instance.Client.CommunicationState == CommunicationStates.Disconnected)
            {
                try
                {
#if DEBUG
                    Thread.Sleep(1000);
#endif
                    ClientInfo.Instance.Client.Connect();
                }
                catch (TimeoutException e)
                {
                    _debug.Log(e.Message);
                }
            }

            PeriodicTask.StartNew(80, RefreshData);

            Sender = new ClientSender(ClientInfo.Instance.Client, ClientInfo.Instance.ReplyMessenger);
            return(this);
        }
Exemplo n.º 2
0
        static void Main()
        {
            Console.WriteLine("Press enter to connect to the server...");
            Console.ReadLine(); //Wait user to press enter

            //Create a client object to connect a server on 127.0.0.1 (local) IP and listens 10085 TCP port
            using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10085)))
            {
                //Create a RequestReplyMessenger that uses the client as internal messenger.
                using (var requestReplyMessenger = new RequestReplyMessenger <IScsClient>(client))
                {
                    requestReplyMessenger.Start(); //Start request/reply messenger
                    client.Connect();              //Connect to the server

                    Console.Write("Write some message to be sent to server: ");
                    var messageText = Console.ReadLine(); //Get a message from user

                    //Send user message to the server and get response
                    var response = requestReplyMessenger.SendMessageAndWaitForResponse(new ScsTextMessage(messageText));

                    Console.WriteLine("Response to message: " + ((ScsTextMessage)response).Text);

                    Console.WriteLine("Press enter to disconnect from server...");
                    Console.ReadLine(); //Wait user to press enter
                }
            }
        }
Exemplo n.º 3
0
        public virtual bool Connect(string remote_ip, int remote_port, int timeout = 10000)
        {
            try
            {
                this.ServerIp   = remote_ip;
                this.ServerPort = remote_port;

                EzWireProtocol protocol = new EzWireProtocol();
                protocol.DataReceived += protocol_DataReceived;//接收到数据,但不一定是message

                _client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(remote_ip, remote_port));
                _client.WireProtocol     = protocol;
                _client.Connected       += client_Connected;
                _client.Disconnected    += client_Disconnected;
                _client.MessageReceived += client_MessageReceived;
                _client.ConnectTimeout   = timeout;
                _client.Connect();

                this._remain_life_number = this.DefaultLifeNumber;

                Helper.start_timer(ref _1s_timer, "1s timer", 1000, _1s_timer_Elapsed);
            }
            catch (Exception ex)
            {
                EzLogger.GlobalLogger.warning(string.Format("{0}{2}{1}{2}",
                                                            ex.Message, ex.StackTrace, Environment.NewLine));

                Dispose();

                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        static void Main()
        {
            Console.WriteLine("Press enter to connect to the server...");
            Console.ReadLine(); //Wait user to press enter

            //Create a client object to connect a server on 127.0.0.1 (local) IP and listens 10085 TCP port
            using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10085)))
            {
                //Create a SynchronizedMessenger that uses the client as internal messenger.
                using (var synchronizedMessenger = new SynchronizedMessenger <IScsClient>(client))
                {
                    synchronizedMessenger.Start(); //Start synchronized messenger messenger
                    client.Connect();              //Connect to the server

                    Console.Write("Write some message to be sent to server: ");
                    var messageText = Console.ReadLine(); //Get a message from user

                    //Send a message to the server
                    synchronizedMessenger.SendMessage(new ScsTextMessage(messageText));

                    //Receive a message from the server
                    var receivedMessage = synchronizedMessenger.ReceiveMessage <ScsTextMessage>();

                    Console.WriteLine("Response to message: " + (receivedMessage.Text));

                    Console.WriteLine("Press enter to disconnect from server...");
                    Console.ReadLine(); //Wait user to press enter
                }
            }
        }
Exemplo n.º 5
0
        public void TestWithScsSentMultipleMessage()
        {
            using (var tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(_bankIp, _bankPort)))
            {
                //bool sent;
                tcpClient.WireProtocol = new HostProtocol();
                tcpClient.Connect();
                //tcpClient.MessageSent += (sender, args) =>
                //{
                //    sent = true;
                //};

                for (int i = 0; i < 10; i++)
                {
                    //sent = false;
                    Thread.Sleep(10);
                    Console.WriteLine("Start sending : " + i);
                    string b      = "08008220000080000000040000001000000001041018080084380861100016030106579944";
                    Byte[] result = _helper.GetBytesWithHeaderLength(b);
                    tcpClient.SendMessage(new HostRawMessage(result));
                    Console.WriteLine("Sent : " + i);

                    //while (!sent) { }
                }
            }
        }
Exemplo n.º 6
0
        public clt_uc()
        {
            InitializeComponent();

            global_class = new global();
            var parser = new FileIniDataParser();

            data = parser.ReadFile("app_set.ini");

            uptime = init_cls.GETUpTime;

            client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(data["NETWORK"]["MULTI_IP"], int.Parse(data["NETWORK"]["MULTI_PORT"])));
            client.MessageReceived += Client_MessageReceived;
            client.Disconnected    += Client_Disconnected;

            refreshUptime.Elapsed  += new ElapsedEventHandler(refreshTime);
            refreshProcess.Elapsed += new ElapsedEventHandler(refreshProcs);
            refreshConn.Elapsed    += RefreshConn_Elapsed;
            refreshHD.Elapsed      += RefreshHD_Elapsed;

            //refreshProcess.Enabled = true;
            refreshHD.Enabled = true;
            refreshHD.Start();
            //refreshProcess.Start();

            ConnectToServer();
            checkUpdate();
        }
 public void Connect(string pIp, int pPort)       // succes = true,  error = false
 {
     this.ClientInformation = ScsClientFactory.CreateClient(new ScsTcpEndPoint(pIp, pPort));
     this.ClientInformation.Connect();
     this._connected = true;
     this.ClientInformation.MessageReceived += this.Client_MessageReceived;
     //this.Text += " verbonden met: " + p_ip;
 }
Exemplo n.º 8
0
 public void Connect(int clientId, string ip, int port)
 {
     _clientId  = clientId;
     _tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port));
     _tcpClient.WireProtocol     = new AtmProtocol();
     _tcpClient.MessageReceived -= OnMessageReceived;
     _tcpClient.MessageReceived += OnMessageReceived;
     _tcpClient.Connect();
 }
Exemplo n.º 9
0
        public ConnectionServices(string ip, int port)
        {
            _tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port));
            _tcpClient.WireProtocol = new HsmProtocol();

            _tcpClient.MessageReceived -= OnMessageReceived;

            _tcpClient.MessageReceived += OnMessageReceived;
            _tcpClient.Connect();
        }
Exemplo n.º 10
0
        public void StartClient()
        {
            //Create a client object to connect a server on 127.0.0.1 (local) IP and listens 10085 TCP port
            client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(Klinik3.Properties.Settings.Default.HostPCName, Klinik3.Properties.Settings.Default.Port));

            client.Connect(); //Connect to the server
            //Console.Write("Write some message to be sent to server: ");
            //var messageText = Console.ReadLine(); //Get a message from user
            ////Send message to the server
            //client.SendMessage(new ScsTextMessage(messageText));
        }
Exemplo n.º 11
0
 /// <summary>
 /// 启动
 /// </summary>
 public void Start()
 {
     tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ServerIP, ServerPort));
     crc       = new ClientReConnecter(tcpClient);
     tcpClient.Disconnected    += new EventHandler(RouteServer_Disconnected);
     tcpClient.Connected       += new EventHandler(RouteServer_Connected);
     tcpClient.ConnectTimeout   = 30;
     tcpClient.MessageReceived += new EventHandler <MessageEventArgs>(RouteServer_MessageReceived);
     tcpClient.MessageSent     += new EventHandler <MessageEventArgs>(RouteServer_MessageSent);
     tcpClient.Connect();
 }
Exemplo n.º 12
0
        public InnerNetworkClient(string Address, int Port)
        {
            BindAddress = Address;
            BindPort    = Port;

            InnerClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(BindAddress, BindPort));
            InnerClient.WireProtocol = new InnerWireProtocol();

            InnerClient.Connected       += OnConnected;
            InnerClient.Disconnected    += OnDisconnected;
            InnerClient.MessageReceived += OnMessageReceived;

            innerNetworkClient = this;
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            Thread th = new Thread(new ThreadStart(SendHandShake));

            th.Start();
            tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint("192.168.10.192", 2000));
            ClientReConnecter crc = new ClientReConnecter(tcpClient);

            tcpClient.Disconnected    += new EventHandler(ExchangeServer_Disconnected);
            tcpClient.Connected       += new EventHandler(ExchangeServer_Connected);
            tcpClient.ConnectTimeout   = 30;
            tcpClient.MessageReceived += new EventHandler <MessageEventArgs>(ExchangeServer_MessageReceived);
            tcpClient.MessageSent     += new EventHandler <MessageEventArgs>(ExchangeServer_MessageSent);
            tcpClient.Connect();
        }
Exemplo n.º 14
0
        static void Main()
        {
            Console.WriteLine("Press enter to connect to server and say Hello world!");
            Console.ReadLine();

            using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10033)))
            {
                client.WireProtocol = new MyWireProtocol(); //Set custom wire protocol!

                client.Connect();
                client.SendMessage(new ScsTextMessage("Hello world!"));

                Console.WriteLine("Press enter to disconnect from server");
                Console.ReadLine();
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// 实例化ServiceMessage
        /// </summary>
        /// <param name="node"></param>
        /// <param name="logger"></param>
        public ServiceRequest(ServerNode node, ILog logger, bool isTimeoutDisconnect)
        {
            this.logger = logger;
            this.node   = node.Key;
            this.ip     = node.IP;
            this.port   = node.Port;

            this.client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port));
            this.client.ConnectTimeout      = 5000;
            this.client.IsTimeoutDisconnect = isTimeoutDisconnect;
            this.client.Disconnected       += client_Disconnected;
            this.client.MessageReceived    += client_MessageReceived;
            this.client.MessageSent        += client_MessageSent;
            this.client.MessageError       += client_MessageError;
            this.client.WireProtocol        = new CustomWireProtocol(node.Compress, node.Encrypt);
        }
Exemplo n.º 16
0
        public bool TcpConnect(string fileDir, string ip, int port, int index = 1)
        {
            var findItem = TcpModels.Find(o => o.Id == index);

            if (findItem == null)
            {
                return(false);
            }
            if (!findItem.IsConnected)
            {
                findItem.IP      = ip;
                findItem.Port    = port;
                findItem.FileDir = fileDir;
                var dt  = DateTime.Now.ToString("yyyyMMddHHmmss");
                var dir = fileDir + "Wan" + index.ToString();
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                //  findItem.TcpStream = new FileStream(dir + "\\" + dt, FileMode.Append, FileAccess.Write);
            }
            try
            {
                //Create a client object to connect a server on 127.0.0.1 (local) IP and listens 10085 TCP port
                findItem.Client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port));
                // client.WireProtocol = new CustomWireProtocol(); //Set custom wire protocol
                //Register to MessageReceived event to receive messages from server.
                findItem.Client.ConnectTimeout   = 5;
                findItem.Client.MessageReceived += (s, e) => Client_MessageReceived(s, e, findItem);
                findItem.Client.Connected       += (s, e) => Client_Connected(s, e, findItem);
                findItem.Client.Disconnected    += (s, e) => Client_Disconnected(s, e, findItem);
                findItem.Client.Connect(); //Connect to the server


                //Send message to the server
                //findItem.Client.SendMessage(new ScsTextMessage("3F", "q1"));

                //client.Disconnect(); //Close connection to server
            }
            catch (Exception ex)
            {
                findItem.Client.Dispose();
                LogHelper.ErrorLog(ex, "连接异常!");
                return(false);
            }
            return(true);
        }
Exemplo n.º 17
0
        public void Start()
        {
            mId          = Config.User.Id;
            mServiceName = Config.User.ServiceName;
            mPort        = Config.User.Port;

            foreach (var server in Config.User.Servers)
            {
                try
                {
                    using (var b = ScsClientFactory.CreateClient(new ScsTcpEndPoint(server.Ip, server.Port)))
                    {
                        b.Connected       += ServerOnConnected;
                        b.Disconnected    += ServerOnDisconnected;
                        b.MessageReceived += ServerOnMessageReceived;

                        b.ConnectTimeout = 2000;
                        b.Connect();
                        mBackEnds.Add(b);

                        mReConnecters.Add(new ClientReConnecter(b));
                    }
                }
                catch (Exception ex)
                {
                    Logger.FatalException("Server " + server.ServiceName + " at " + server.Ip + ":" + server.Port + " can not reached.", ex);
                    return;
                }
            }

            try
            {
                mFrontEndServer = ScsServerFactory.CreateServer(new ScsTcpEndPoint(mPort));
                mFrontEndServer.WireProtocolFactory = new ProtobufSerializationProtocolFactory();

                mFrontEndServer.ClientConnected    += ClientConnected;
                mFrontEndServer.ClientDisconnected += ClientDisconnected;

                mFrontEndServer.Start();
            }
            catch (Exception ex)
            {
                Logger.FatalException("Server start failed.", ex);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// 启动
        /// </summary>
        public void Start()
        {
            // handle recieved message
            ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRecvMsg_Thread));

            //shake handle with server
            ThreadPool.QueueUserWorkItem(new WaitCallback(SharkHands_Thread), Controller.GetInstance().SharkHandsInterval);

            tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ExchangeServerIP, ExchangeServerPort));
            ClientReConnecter crc = new ClientReConnecter(tcpClient);

            tcpClient.Disconnected    += new EventHandler(ExchangeServer_Disconnected);
            tcpClient.Connected       += new EventHandler(ExchangeServer_Connected);
            tcpClient.ConnectTimeout   = 30;
            tcpClient.MessageReceived += new EventHandler <MessageEventArgs>(ExchangeServer_MessageReceived);
            tcpClient.MessageSent     += new EventHandler <MessageEventArgs>(ExchangeServer_MessageSent);
            tcpClient.Connect();
        }
        public static void Run()
        {
            Console.WriteLine("Press enter to connect to server and send " + Consts.MessageCount + " messages.");
            Console.ReadLine();

            using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10033)))
            {
                client.Connect();

                for (var i = 0; i < Consts.MessageCount; i++)
                {
                    client.SendMessage(new ScsTextMessage("Hello from client!"));
                }

                Console.WriteLine("Press enter to disconnect from server");
                Console.ReadLine();
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Connects to the server.
        /// It automatically Logins to server if connection success.
        /// </summary>
        private void Connect(string serverIpAddress, int serverTcpPort)
        {
            //Disconnect if currently connected
            Disconnect();

            //Create a SCS client to connect to SCS server
            _scsClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(serverIpAddress, serverTcpPort));

            _scsClient.ConnectTimeout = 3;

            //Register events of SCS client
            _scsClient.Connected       += this.ScsClientConnected;
            _scsClient.Disconnected    += this.ScsClientDisconnected;
            _scsClient.MessageReceived += this.ScsClientMessageReceived;


            //Connect to the server
            _scsClient.Connect();
        }
Exemplo n.º 21
0
        public void Start()
        {
            try
            {
                Log.Warn("Connecting to server at {0} : {1} ", Category.System, IpAddress, Port);
                _client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(IpAddress, Port));

                _client.WireProtocol = new AuthProtocol();

                _client.MessageReceived += OnReceiveMessage;
                _client.Connected       += OnConnected;
                _client.Disconnected    += OnDisconected;
                _client.Connect();
            }
            catch (Exception ex)
            {
                Log?.Exception(ex, "Starting Client");
            }
        }
Exemplo n.º 22
0
        public static void SendAction(string ip, int port, int?operationId, string actionName, int connectionTimeout = 3000)
        {
            string message = $"{operationId},{actionName},0";

            //Create a client object to connect a server
            using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port)))
            {
                //Create a RequestReplyMessenger that uses the client as internal messenger.
                using (var requestReplyMessenger = new RequestReplyMessenger <IScsClient>(client))
                {
                    requestReplyMessenger.Start();         //Start request/reply messenger
                    client.ConnectTimeout = connectionTimeout;
                    client?.Connect();                     //Connect to the server
                    Thread.Sleep(700);
                    //Send user message to the server
                    requestReplyMessenger.SendMessage(new ScsTextMessage(message));
                }
            }
        }
Exemplo n.º 23
0
        //---methods

        public ScsClient(string login, string ip, int tcpPort)
        {
            _login = login;

            //Синхронная очередь клиентских событий
            _eventQueue = new ConcurrentEventQueue();

            _msgReaders = new MsgReadersCollection();
            _msgReaders.RegisterMsgReader <AuthenticationSuccesMessage>(AuthenticationSuccessMsgReader);

            //Синхронная очередь msg с сервера
            _msgQueue = new ConcurrentMsgQueue(_msgReaders);

            _client               = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, tcpPort));
            _client.Connected    += Client_Connected;
            _client.Disconnected += Client_Disconnected;

            _msgQueue.AddMessenger(_client);
        }
Exemplo n.º 24
0
        private void ConnectClick(object sender, RoutedEventArgs e)
        {
            string ip = txtIp.Text.Trim();

            if (string.IsNullOrWhiteSpace(ip) || string.IsNullOrWhiteSpace(txtPort.Text.Trim()))
            {
                MessageBox.Show("请填写IP及端口号!");
                return;
            }
            int port = 0;

            if (!int.TryParse(txtPort.Text.Trim(), out port))
            {
                MessageBox.Show("端口号必须为数字!");
                return;
            }
            try
            {
                //Create a client object to connect a server on 127.0.0.1 (local) IP and listens 10085 TCP port
                client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port));
                // client.WireProtocol = new CustomWireProtocol(); //Set custom wire protocol
                //Register to MessageReceived event to receive messages from server.
                client.MessageReceived += Client_MessageReceived;
                client.Connected       += Client_Connected;
                client.Disconnected    += Client_Disconnected;
                client.Connect();                 //Connect to the server

                var messageText = "连接服务端成功!";     //Get a message from user
                //Send message to the server
                client.SendMessage(new ScsTextMessage(messageText, "q1"));

                //client.Disconnect(); //Close connection to server
            }
            catch (Exception)
            {
                client.Dispose();
                MessageBox.Show("连接异常!");
            }
        }
Exemplo n.º 25
0
        private void ConnectAsync()
        {
            while (true)
            {
                try
                {
                    if (_tcpClient == null)
                    {
                        _tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(Config.PartnerIpAddress, Config.PartnerPort));
                        _tcpClient.WireProtocol = new HostProtocol();
                    }
                    if (_tcpClient.CommunicationState == CommunicationStates.Disconnected)
                    {
                        _coreSvc.Disconnect();
                        _log.Warn("Connecting to Partner...");
                        _tcpClient.Connected       -= Connected;
                        _tcpClient.Disconnected    -= Disconnected;
                        _tcpClient.MessageReceived -= OnMessageReceived;
                        _tcpClient.MessageSent     -= MessageSent;

                        _tcpClient.Connected       += Connected;
                        _tcpClient.Disconnected    += Disconnected;
                        _tcpClient.MessageReceived += OnMessageReceived;
                        _tcpClient.MessageSent     += MessageSent;
                        _tcpClient.Connect();
                    }
                    else if (_tcpClient.CommunicationState == CommunicationStates.Connected)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    _log.Error(ex.Message);
                    Close();
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Отправка сообщения по сети и ожидание ответа
        /// </summary>
        public static string SendActionAndWaitForResponse(string ip, int port, int?operationId, string actionName, int connectionTimeout = 3000, int responseTimeOut = 5000)
        {
            string result  = null;
            string message = $"{operationId},{actionName},1";

            //Create a client object to connect a server
            using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port)))
            {
                //Create a RequestReplyMessenger that uses the client as internal messenger.
                using (var requestReplyMessenger = new RequestReplyMessenger <IScsClient>(client))
                {
                    requestReplyMessenger.Start();        //Start request/reply messenger
                    client.ConnectTimeout = connectionTimeout;
                    client.Connect();                     //Connect to the server
                    Thread.Sleep(700);
                    //Send user message to the server and get response
                    var response = requestReplyMessenger.SendMessageAndWaitForResponse(new ScsTextMessage(message), responseTimeOut);

                    result = ((ScsTextMessage)response).Text;
                }
            }
            return(result);
        }
        public static void Run()
        {
            Console.WriteLine("Press enter to connect to server and send " + Consts.MessageCount + " messages.");
            Console.ReadLine();

            using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10033)))
            {
                using (var synchronizedMessenger = new SynchronizedMessenger <IScsClient>(client))
                {
                    synchronizedMessenger.Start();
                    client.Connect();

                    for (var i = 0; i < Consts.MessageCount; i++)
                    {
                        synchronizedMessenger.SendMessage(new ScsTextMessage("Hello from client!"));
                        var reply = synchronizedMessenger.ReceiveMessage <ScsTextMessage>();
                    }
                }

                Console.WriteLine("Press enter to disconnect from server");
                Console.ReadLine();
            }
        }
Exemplo n.º 28
0
        static void Main()
        {
            //Create a client object to connect a server on 127.0.0.1 (local) IP and listens 10085 TCP port
            var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10085));

            //Register to MessageReceived event to receive messages from server.
            client.MessageReceived += Client_MessageReceived;

            Console.WriteLine("Press enter to connect to the server...");
            Console.ReadLine(); //Wait user to press enter

            client.Connect();   //Connect to the server

            Console.Write("Write some message to be sent to server: ");
            var messageText = Console.ReadLine(); //Get a message from user

            //Send message to the server
            client.SendMessage(new ScsTextMessage(messageText));

            Console.WriteLine("Press enter to disconnect from server...");
            Console.ReadLine();  //Wait user to press enter

            client.Disconnect(); //Close connection to server
        }
Exemplo n.º 29
0
 private void Init()
 {
     _spIp   = Settings.Default.SpIP;
     _spPort = Settings.Default.SpPort;
     Client  = ScsClientFactory.CreateClient(new ScsTcpEndPoint(SpIP, SpPort));
 }
Exemplo n.º 30
0
        public static bool CheckConnectionMessage(string connectString)
        {
            try
            {
                using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(MainWindow.launcherConfig.ServerIP, Convert.ToInt32(MainWindow.launcherConfig.ServerPort))))
                {
                    client.WireProtocol = new KeyProtocol();


                    using (var synchronizedMessenger = new SynchronizedMessenger <IScsClient>(client))
                    {
                        //setup response manager
                        synchronizedMessenger.Start();

                        client.Connect();

                        synchronizedMessenger.SendMessage(new ScsTextMessage(connectString));
                        var replyPacket = synchronizedMessenger.ReceiveMessage <ScsTextMessage>();
                        if (replyPacket == null)
                        {
                            client.Disconnect();
                            return(false);
                        }
                        //
                        string data = replyPacket.Text;
                        switch (data)
                        {
                        //LoginPacket Response
                        case "4099":    //Auth FAILED PASS
                            PrintMessage("Sorry! Authorization for this Account failed, is your Password correct?");
                            client.Disconnect();
                            return(false);

                        case "4098":   //Auth OK
                            PrintMessage("Yes! Authorization for this Account was successfull!");
                            client.Disconnect();
                            return(true);

                        case "4100":    //Account Unbanned
                            PrintMessage("Yes! Your Account got Unbanned, have fun to play!");
                            client.Disconnect();
                            return(true);

                        case "4101":    //Account Banned
                            PrintMessage("Sorry! but your Account is Banned, please contact the support for more information!");
                            client.Disconnect();
                            return(false);

                        case "4102":    //Account Online
                            PrintMessage("Wtf! You are already Online, if its not you please contact the Support!");
                            client.Disconnect();
                            return(false);

                        //Register Packet Response
                        case "8194":    //Account already Exists
                            PrintMessage("Sorry! Account Registration failed, Account already exists!");
                            client.Disconnect();
                            return(false);

                        case "8195":    //Account creation successfull
                            PrintMessage("Yes! Registration for this Account was successful!");
                            client.Disconnect();
                            return(true);

                        default:
                            PrintMessage("PacketFailure %$§&*$" + replyPacket.Text);
                            client.Disconnect();
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connecting error!\n" + ex, "Error");
                return(false);
            }
        }