Example #1
0
        public static void Start(string name, int port)
        {
            Type requiredType = typeof(IMessenger);

            remoteObject = (IMessenger)Activator.GetObject(requiredType, $"tcp://localhost:{port}/{name}");
            remoteObject.ClearMessage("");
        }
        private static void RefreshMessages()
        {
            try
            {
                var requiredType = typeof(IMessenger);
                var url          = $"tcp://localhost:{serverPort}/{serverName}";
                remoteObject = (IMessenger)Activator.GetObject(requiredType, url);

                threadRunning = true;
                lock (lockObj) remoteObject.ClearMessage(id);
                Console.WriteLine("[CardOrganizer] Starting client");
            }
            catch (Exception ex)
            {
                Console.WriteLine("[CardOrganizer] Server not found");
                Console.WriteLine(ex);
            }

            while (threadRunning)
            {
                try
                {
                    lock (lockObj)
                    {
                        var msg = remoteObject.GetMessage(id);
                        if (msg != null)
                        {
                            var message = MessagePackSerializer.Deserialize <MsgObject>(msg);
                            message.Print();
                            messageAction(message, subId);
                        }
                    }

                    Thread.Sleep(100);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("ERROR: Old bug in MessagePack-CSharp (Duplicate type name within an assembly, issue #127)\n" +
                                      "Must use a fixed Assembly-CSharp-firstpass.dll for this to work with scriptloader in KK\n" + ex);
                    threadRunning = false;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    threadRunning = false;
                }
            }

            Console.WriteLine("[CardOrganizer] Stopping client");
        }