Program.cs
上传用户:zhangkuixh
上传日期:2013-09-30
资源大小:5473k
文件大小:3k
源码类别:

搜索引擎

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. using System.Net;
  6. using System.Net.Sockets;
  7. using System.IO;
  8. /*
  9.       '       迅龙中文分类搜索引擎  v0.6
  10.       '
  11.       '        LGPL  许可发行
  12.       '
  13.       '       宁夏大学  张冬 康彩  zd4004@163.com
  14.       ' 
  15.       '        官网 http://blog.163.com/zd4004/
  16.  */
  17. namespace XunLong.NewWebServer
  18. {
  19.     class Program
  20.     {
  21.         static void Main(string[] args)
  22.         {
  23.             Console.WriteLine("  >------------------------------------------<");
  24.             Console.WriteLine("  >------------------------------------------<");
  25.             Console.WriteLine("  >          列表中文搜索引擎_组件v0.6       <");
  26.             Console.WriteLine("  >                Web Server                <");
  27.             Console.WriteLine("  >------------------------------------------<");
  28.             Console.WriteLine("  >------------------------------------------<");
  29.             Console.WriteLine("=============================================");
  30.             Console.WriteLine("=                                           =");
  31.             Console.WriteLine("迅龙Web服务器");
  32.             Console.WriteLine("=                                           =");
  33.             Console.WriteLine("=============================================");
  34.             //读取配置
  35.             string k_c_path = args[0];
  36.             Console.WriteLine("--》Web服务器_加载配置文件: " + k_c_path);
  37.             XunLong.CongifData.Config.InitConfigData(k_c_path);
  38.             int Set_Port = XunLong.CongifData.Config.WebPort;
  39.              string pathc = XunLong.CongifData.Config.WebSite;
  40.              string Set_IP = XunLong.CongifData.Config.WebIP;
  41.                    /// <summary>
  42.             /// 帮定的地址 不含 http://
  43.              /// </summary>
  44.            string HTTPURL =XunLong.CongifData.Config.WebIP+":"+XunLong.CongifData.Config.WebPort.ToString();
  45.              IPAddress myIP;
  46.              IPEndPoint iep;
  47.              try
  48.              {
  49.                  myIP = IPAddress.Parse(Set_IP);
  50.                  iep = new IPEndPoint(myIP, Set_Port);
  51.              }
  52.              catch
  53.              {
  54.                  Console.WriteLine("你输入的服务器名或端口号格式不正确,请重新输入!");
  55.                  return;
  56.              }
  57.          XF:
  58.              ClassRUN_XZ.Init(k_c_path);
  59.            ClassRUN_XZ.SetHTTPURL(HTTPURL);
  60.             //定义端口号
  61.              TcpListener tcplistener = new TcpListener(iep);
  62.              Console.WriteLine("侦听端口号: " + Set_Port.ToString());
  63.              tcplistener.Start();
  64.   
  65.              Console.WriteLine("绑定地址: "+ HTTPURL);
  66.             //侦听端口号
  67.             while (true)
  68.             {
  69.                 try
  70.                 {
  71.                     Socket socket = tcplistener.AcceptSocket();
  72.                     //并获取传送和接收数据的Scoket实例
  73.                     CWebServer CWebServer_one = new CWebServer(socket, pathc);
  74.                   
  75.                     //类实例化
  76.                     Thread T = new Thread(new ThreadStart(CWebServer_one.Run));
  77.                     //创建线程
  78.                     T.Start();
  79.                     //启动线程
  80.                 }
  81.                 catch
  82.                 {
  83.                     goto XF;
  84.                 }
  85.             }
  86.         }
  87.     }
  88. }