示例#1
0
        private static void Send()
        {
            object obj = null;

            while (true)
            {
                if (sending_list.Count > 0)
                {
                    lock (lock_obj)
                    {
                        obj = sending_list.Dequeue();
                    }
                }
                if (obj != null)
                {
                    try
                    {
                        client.Send(obj);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.ToString());
                    }
                    finally
                    {
                        obj = null;
                    }
                }
                Thread.Sleep(1);
            }
        }
示例#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));
            }
        }
示例#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);
                 * }
                 */
            }
        }