日期:2014-05-17  浏览次数:20931 次

C# C/S 客户端与服务器端交户
服务器端代码:
namespace Server
{
    
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        /// 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form3());
            Application.Run(new ServerForm());
        }
    }
}


public void run()
        {
            ipIpep = new IPEndPoint(IPAddress.Any,6666);   //服务器从6666端口接收客户端的登陆请求
            receiveUdpClient = new UdpClient(ipIpep);
            sendUdpClient = new UdpClient();
            
            receiveState = new UdpState();
            receiveState.udpClient = receiveUdpClient;
            receiveState.ipEndPoint = ipIpep;

            sendState = new UdpState();
            sendState.udpClient = sendUdpClient;
            sendState.ipEndPoint = remoteIpep;   
            ReceiveMsg();       
         }    
            public void ReceiveMsg()
            {