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

搜索引擎

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. using System.Net.Sockets;
  6. using System.Collections;
  7. using System.Threading;
  8. /*
  9.       '       迅龙中文分类搜索引擎  v0.6
  10.       '
  11.       '        LGPL  许可发行
  12.       '
  13.       '       宁夏大学  张冬 康彩  zd4004@163.com
  14.       ' 
  15.       '        官网 http://blog.163.com/zd4004/
  16.  */
  17. namespace XunLong.NewXWord
  18. {
  19.     /// <summary>
  20.     /// 服务数据接入类
  21.     /// </summary>
  22.     class ClassRunIt
  23.     {
  24.       
  25.         /// <summary>
  26.         /// 是否监听
  27.         /// </summary>
  28.         public bool isListen = true;
  29.         public void StartListen()
  30.         {
  31.             IPAddress myIP;
  32.             IPEndPoint iep;
  33.             try
  34.             {
  35.                 myIP = IPAddress.Parse(XunLong.CongifData.Config.xWordCacheServer);
  36.                 iep = new IPEndPoint(myIP, XunLong.CongifData.Config.xWordCacheServerPort);
  37.             }
  38.             catch
  39.             {
  40.                 Console.WriteLine("你输入的服务器名或端口号格式不正确,请重新输入!");
  41.                 return;
  42.             }
  43.             Console.WriteLine("开始监听...");
  44.             Console.WriteLine(" 在 " + XunLong.CongifData.Config.xWordCacheServer + " : " + XunLong.CongifData.Config.xWordCacheServerPort.ToString());
  45.             Console.WriteLine("********************************************");
  46.             Console.WriteLine("");
  47.             ClassCMD.Init();
  48.             StartXD:
  49.        
  50.              //定义端口号
  51.              TcpListener tcplistener = new TcpListener(iep);         
  52.              tcplistener.Start();
  53.             //侦听端口号
  54.              while (true)
  55.              {
  56.                  try
  57.                  {
  58.                      Socket socket = tcplistener.AcceptSocket();
  59.                      socket.ReceiveTimeout = 30000;
  60.                      //并获取传送和接收数据的Scoket实例
  61.                      NewLinkClass CWebServer_one = new NewLinkClass(socket);
  62.                      //类实例化
  63.                      Thread TX = new Thread(new ThreadStart(CWebServer_one.Run));
  64.                      //创建线程
  65.                      TX.Start();
  66.                      //启动线程    
  67.                  }
  68.                  catch
  69.                  {
  70.                      goto StartXD;
  71.                  }
  72.              }
  73.         }
  74.     }
  75. }