Exemple #1
0
        public static bool Connect(string ip, int port)
        {
            client = new NetWorkClient(ip, port);
            bool ans = client.Connect();

            if (isClient)
            {
                client.answer += client_answer;
                client.BeginListener();

                var t = new Thread(Send);
                t.IsBackground = true;
                t.Start();
            }
            return(ans);
        }
Exemple #2
0
        void btn_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Friend f = null;

            foreach (var item in App.data.FriendList)
            {
                if (item.Value.isSelected)
                {
                    f              = (Friend)item.Value;
                    client         = new NetWorkClient(f.ip.ToString(), 6537);
                    client.answer += GetAnswers; //托管(回调)
                    client.Connect();            //开始连接
                    client.BeginListener();
                    break;
                }
            }
            if (f == null)
            {
                f              = API.Me;
                server         = new NetWorkServer(f.ip.ToString(), 6537);
                server.answer += Answer; //如果收到信息,则执行Answer(托管)
                server.BeginListener();  //开始监听
            }
            if (!f.Equals(API.Me))
            {
                client.Send("Info");
            }
            mainWindow = new MainWindow(f);
            mainWindow.Show();
            mainWindow.Focus();

            var func = runhandle;

            if (func != null)
            {
                func(this, new PluginRunEvent.PluginRunEventArgs(this));
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            string name = ConfigurationManager.AppSettings["name"];
            string ip   = ConfigurationManager.AppSettings["ip"];
            int    port = int.Parse(ConfigurationManager.AppSettings["port"]);

            client         = new NetWorkClient(ip, port); //链接服务器,端口为9999
            client.answer += GetAnswers;                  //托管(回调)
            client.Connect();                             //开始连接
            client.BeginListener();
            string command;

            Console.WriteLine("welcome to the chating room");
            while (true)
            {
                //不断获取指令
                command = Console.ReadLine();

                String str = name + ":\n  " + command + "\n";
                // Console.WriteLine(str);
                client.Send(str);  //发过去

                /*
                 * if (command == "send")//若输入'send'
                 * {
                 *  //新构建Image对象
                 *  Image bitmap = Image.FromFile("ysn.gif");
                 *  client.Send(bitmap);  //发过去
                 * }
                 *
                 * if (command == "message")//若输入'send'
                 * {
                 *  string hello = "HelloWorld";
                 *  client.Send(hello);
                 * }
                 */
            }
        }
Exemple #4
0
        public static bool Connect(string ip, int port)
        {
            bool ans = false;

            try
            {
                client = new NetWorkClient(ip, port);
                ans    = client.Connect();
                if (isClient)
                {
                    client.answer += client_answer;
                    client.BeginListener();

                    var t = new Thread(Send);
                    t.IsBackground = true;
                    t.Start();
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show("Client.Connect" + e1.Message);
            }
            return(ans);
        }