点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 企业网站>> .NET SOCKET聊天源码>> 源文件浏览
[商业版 216金币] WinForm,下载次数:0 次 | 关键字: .Net Socket Socket聊天

源码截图

源码目录树

当前路径:chatServer/chatServer/mainFrm.cs     using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace chatServer
{
    public partial class mainFrm : Form
    {
        // Thread signal.     
        public static ManualResetEvent allDone = new ManualResetEvent(false);

        //用户列表
        private List<User> userList = new List<User>();

        //本机IP
        string IP = "192.168.0.153";
        //监听端口
        int port = 2000;
        Socket listener;

        //
        Thread myThread;
        

        //0 close 1 working
        int status = 0;

        public mainFrm()
        {
            InitializeComponent();
        }

        private delegate void AddItemToListBoxDelegate(string str);

        private void AddItemToListBox(string str)
        {
            if (listBox1.InvokeRequired)
            {
                AddItemToListBoxDelegate d = AddItemToListBox;
                listBox1.Invoke(d, str);
            }
            else
            {
                listBox1.Items.Add(str);
                listBox1.SelectedIndex = listBox1.Items.Count - 1;
                listBox1.ClearSelected();
            }

        }

        private void mainFrm_Load(object sender, EventArgs e)
        {
            status = 0;
            btnStop.Enabled = false;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            status = 1;    
            btnStop.Enabled = true;
            btnStart.Enabled = false;

            myThread = new Thread(startListen);
            myThread.Start();
        }

        private void startListen()
        {
            IPAddress ipAddress = IPAddress.Parse(IP);
            IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);

            listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            ...
对不起,完整源码文件,请先购买后再查看
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途) 企业QQ:2852517674
地址:北京市海淀区中关村鼎好大厦A座二层 邮编:100080
Room A-801,Dinghao Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2015. 京ICP备09089570号 | 京公网安备11010702000869号
分享该页面
关闭侧边栏