当前位置: 首页>>代码示例>>C#>>正文


C# TcpListener.BeginAcceptSocket方法代码示例

本文整理汇总了C#中System.Net.Sockets.TcpListener.BeginAcceptSocket方法的典型用法代码示例。如果您正苦于以下问题:C# TcpListener.BeginAcceptSocket方法的具体用法?C# TcpListener.BeginAcceptSocket怎么用?C# TcpListener.BeginAcceptSocket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Sockets.TcpListener的用法示例。


在下文中一共展示了TcpListener.BeginAcceptSocket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            GMSKeys.Initialize();

            {
                // Quick test
                ITEMS = new Dictionary<short, ItemEquip>();
                ITEMS.Add(1, new ItemEquip(1113017)
                {
                    StatusFlags = 0x0714,
                    Potential1 = 40356,
                    Potential2 = 30041,
                    Potential3 = 30044,
                    Potential4 = 12011,
                    Potential5 = 2014,
                    Potential6 = 2014,
                    SocketState = 0x00FF,
                    Nebulite2 = 1001,
                    Nebulite1 = 2001,
                    Nebulite3 = 3400,

                });

                //File.WriteAllText("import.xml", ITEMS.Serialize());

                if (File.Exists("import.xml"))
                {
                    ITEMS = File.ReadAllText("import.xml").Deserialize<Dictionary<short, ItemEquip>>();
                }
            }

            if (ITEMS == null)
                ITEMS = new Dictionary<short, ItemEquip>();

            {
                TcpListener listener = new TcpListener(System.Net.IPAddress.Any, 8484);
                listener.Start();

                AsyncCallback EndAccept = null;
                EndAccept = (a) =>
                {
                    new Client(listener.EndAcceptSocket(a));

                    Console.WriteLine("accepted");

                    listener.BeginAcceptSocket(EndAccept, null);
                };

                listener.BeginAcceptSocket(EndAccept, null);
            }



            Console.ReadLine();
        }
开发者ID:diamondo25,项目名称:mapler.me,代码行数:55,代码来源:Program.cs

示例2: Connect4Service

        private Connect4ClientConnection waiting; //Player 1 - put into a game as soon as Player 2 is identified. Set to null once the game starts

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructs a new Connect4Service object. Takes values to set the port it listens on,
        /// as well as a time limit for games held on this server.
        /// Throws InvalidOperationException if timelimit &lt; 1, or the port number is out of range
        /// or already being listened on.
        /// </summary>
        /// <param name="portNumber">Port for the server to listen on</param>
        /// <param name="timeLimit">Time limit for users in games on this server</param>
        public Connect4Service(int portNumber, int _timeLimit, WhoGoesFirst _choosingMethod)
        {
            if (_timeLimit <= 0)
            {
                throw new InvalidOperationException("time limit must be positive");
            }
            if (portNumber > IPEndPoint.MaxPort || portNumber < IPEndPoint.MinPort)
            {
                throw new InvalidOperationException("invalid port number");
            }
            choosingMethod = _choosingMethod;
            games = new List<Connect4Game>();
            needToIdentify = new List<Connect4ClientConnection>();
            waiting = null;
            timeLimit = _timeLimit;
            server = new TcpListener(IPAddress.Any, portNumber);
            try
            {
                server.Start();
            }
            catch (SocketException)
            {
                throw new InvalidOperationException("port already taken (or something like that)");
            }

            server.BeginAcceptSocket(ConnectionRequested, null);
            isShuttingDown = false;
        }
开发者ID:sphippen,项目名称:connect4,代码行数:42,代码来源:Connect4Service.cs

示例3: BoggleServer

        /// <summary>
        /// Constructor used to initialize a new BoggleServer. This will initialize the GameLength
        /// and it will build a dictionary of all of the valid words from the DictionaryPath. If an
        /// optional string was passed to this application, then it will build a BoggleBoard from
        /// the supplied string. Otherwise it will build a BoggleBoard randomly.
        /// </summary>
        /// <param name="GameLength">The length that the Boggle game should take.</param>
        /// <param name="DictionaryPath">The filepath to the dictionary that should be used to
        /// compare words against.</param>
        /// <param name="OptionalString">An optional string to construct a BoggleBoard with.</param>
        public BoggleServer(int GameLength, string DictionaryPath, string OptionalString)
        {
            try
            {
                this.UnderlyingServer = new TcpListener(IPAddress.Any, 2000);
                this.GameLength = GameLength;
                this.DictionaryWords = new HashSet<string>(File.ReadAllLines(DictionaryPath));
                this.WaitingPlayer = null;

                this.CommandReceived = new Object();
                this.ConnectionReceivedLock = new Object();

                if (OptionalString != null)
                    this.OptionalString = OptionalString;

                Console.WriteLine("The Server has Started on Port 2000");

                // Start the server and begin accepting clients.
                UnderlyingServer.Start();
                UnderlyingServer.BeginAcceptSocket(ConnectionReceived, null);

            }

            // If any exception occured when starting the sever or connecting clients,
            // print out an error message and the stacktrace where the error occured.
            catch (Exception e)
            {
                Console.WriteLine("An Exception Occured When Building the BoggleServer:");
                Console.WriteLine(e.ToString());
            }
        }
开发者ID:jon-whit,项目名称:PS8,代码行数:41,代码来源:BoggleServer.cs

示例4: Start

 public void Start()
 {
     _stop = false;
     _listener = new TcpListener(IPAddress.Any, _port);
     _listener.Start();
     _listener.BeginAcceptSocket(OnAcceptSocket, null);
 }
开发者ID:hide1980,项目名称:mdcm,代码行数:7,代码来源:HL7v2Server.cs

示例5: ConnectionManager

        /// <summary>
        /// Constructor to create the list of connects and create
        /// a new thread to wait/accept new connections
        /// </summary>
        public ConnectionManager(String host, String p)
        {
            Log.WriteMessage("WhitStream Server Started.", Log.eMessageType.Normal);
            m_ipAddress = IPAddress.Parse(host);
            m_listenPort = int.Parse(p);

            //Initialize the list to hold no connections and default capacity
            m_connectionList = new List<Connection>();

            //Initialize the list to hold all ports from 4001 to 4010
            m_availablePorts = new Queue<int>(10);
            for (int i = 4001; i <= 4010; i++)
            {
                m_availablePorts.Enqueue(i);
            }

            Log.WriteMessage("Waiting for connections....", Log.eMessageType.Debug);

            //Register a new TcpListener
            m_incomingListener = new TcpListener(m_ipAddress, m_listenPort);
            m_incomingListener.Start();
            m_incomingListener.BeginAcceptSocket(new AsyncCallback(Accept_Socket), null);

            m_checkThread = new Thread(CheckConnections);
            m_checkThread.Start();
        }
开发者ID:ptucker,项目名称:WhitStream,代码行数:30,代码来源:Util.cs

示例6: Framework

        /// <summary>
        /// Creates a new NPCServer
        /// </summary>
        internal Framework(string OptionsFile = "settings.ini")
        {
            // Default PM
            this.NCMsg = CString.tokenize ("I am the npcserver for\nthis game server. Almost\nall npc actions are controled\nby me.");

            // Create Compiler
            Compiler = new GameCompiler (this);

            // Create Player Manager
            PlayerManager = new Players.PlayerList (this, GSConn);
            AppSettings settings = AppSettings.GetInstance ();
            settings.Load (OptionsFile);

            // Connect to GServer
            GSConn = new GServerConnection (this);

            this.ConnectToGServer();

            // Setup NPC-Control Listener
            cNCAccept = new AsyncCallback (NCControl_Accept);
            this.UPnPOpenPort();
            NCListen = new TcpListener (IPAddress.Parse (this.LocalIPAddress ()), settings.NCPort);
            NCListen.Start ();
            NCListen.BeginAcceptSocket (cNCAccept, NCListen);

            settings.Save ();

            // Setup Timer
            //timeBeginPeriod(50);
            //TimerHandle = new TimerEventHandler(RunServer);
            //TimerId = timeSetEvent(50, 0, TimerHandle, IntPtr.Zero, EVENT_TYPE);
        }
开发者ID:dufresnep,项目名称:gs2emu-googlecode,代码行数:35,代码来源:NPCServer.cs

示例7: StartListener

 public void StartListener(string ip,int port)
 {
     socket = new Socket(SocketType.Stream,ProtocolType.Tcp);
     listener = new TcpListener(new IPEndPoint(IPAddress.Parse(ip), port));
     listener.Start();
     listener.BeginAcceptSocket(clientConnect, listener);
 }
开发者ID:aa43a,项目名称:eklink,代码行数:7,代码来源:TCPiaSer.cs

示例8: BoggleServer

        /// <summary>
        /// Creates a BoggleServer that listens for connections on port 2000.
        /// </summary>
        public BoggleServer(int gameTime, HashSet<string> dictionary, string boardConfiguration)
        {
            // Initialize fields.
            _PORT = 2000;
            _server = new TcpListener(IPAddress.Any, _PORT);
            _waitingPlayer = null;
            _allMatches = new HashSet<Match>();
            _lock = new object();
            _gameTime = gameTime;
            _dictionary = dictionary;
            _boardConfiguration = boardConfiguration;

            // Start the server.
            _server.Start();

            // Start listening for a client to connect.
            _server.BeginAcceptSocket(ConnectionReceived, null);

            // Create a timer with a one second interval.
            timer = new System.Timers.Timer(1000);

            // Hook up the Elapsed event for the timer. 
            timer.Elapsed += OneSecondHasPassed;
            timer.Enabled = true;

            // Keep this program alive
            Thread t = new Thread(stayAlive);
            t.Start();
        }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:32,代码来源:BoggleServer.cs

示例9: StandardTcpServer

 //----------------------------------------------------------------------
 //Construction, Destruction
 //----------------------------------------------------------------------
 /// <summary>
 /// Creating server socket
 /// </summary>
 /// <param name="port">Server port number</param>
 public StandardTcpServer(int port)
 {
     connectedSockets = new Dictionary<IPEndPoint, Socket>();
     tcpServer = new TcpListener(IPAddress.Any, port);
     tcpServer.Start();
     tcpServer.BeginAcceptSocket(EndAcceptSocket, tcpServer);
 }
开发者ID:RoboTutor,项目名称:SpeechServer,代码行数:14,代码来源:StdTcpServer.cs

示例10: resetSocketB_Click

        void resetSocketB_Click(object sender, EventArgs e)
        {
            foreach (var item in myList)
            {
                item.Stop();
            }
            myList.Clear(); 

            IPAddress ipAd = IPAddress.Parse(SettingsWin.host.Text);
            // use local m/c IP address, and 
            // use the same in the client

            /* Initializes the Listener */


            //TODO : make handle multi listeners  !! 
            String [] a = SettingsWin.Port.Text.Split(','); 
            foreach (String portt in a ) {
                try {

                    var tempList = new TcpListener(IPAddress.Any, int.Parse(portt));
                    tempList.Start(); 
                    tempList.BeginAcceptSocket(this.AcceptClient, tempList);
                    myList.AddLast(tempList); 
                }
                catch { 
                }
            }
              

            
        }
开发者ID:TheBugMaker,项目名称:Payload-Client,代码行数:32,代码来源:Mainwin.cs

示例11: Mainwin

        public Mainwin()
        {
            
            InitializeComponent();
            cms = this.contextMenuStrip1;  // providing a cms for rows 
            for (int i = 0; i < 21; i++) {
                this.grid1.addRow(); 
            
            }
            Host = SettingsWin.host.Text;
            ports = int.Parse(SettingsWin.Port.Text ) ;

            SettingsWin.resetSocketB.Click += resetSocketB_Click;

            IPAddress ipAd = IPAddress.Parse("127.0.0.1");
            // use local m/c IP address, and 
            // use the same in the client

            /* Initializes the Listener */
            var tempList = new TcpListener(IPAddress.Any, 5202); 
            myList.AddLast(tempList);
            tempList.Start();
           tempList.BeginAcceptSocket(this.AcceptClient,tempList); 
            
            timer1.Start(); 


        }
开发者ID:TheBugMaker,项目名称:Payload-Client,代码行数:28,代码来源:Mainwin.cs

示例12: StartProcessing

		public override void StartProcessing()
		{
			_options.Validate();

			_listener = new TcpListener(_options.Endpoint);
			_listener.Start();
			_listener.BeginAcceptSocket(AcceptCallback, _listener);
		}
开发者ID:NiclasOlofsson,项目名称:HIE,代码行数:8,代码来源:TcpReceiveEndpoint.cs

示例13: Start

		internal bool Start(ushort port) {
			if (Running) { throw new Exception("Listener is already running."); }
			listen = new TcpListener(IPAddress.Any,port);
			try { listen.Start(); }
			catch { Stop(); return false; }
			listen.BeginAcceptSocket(new AsyncCallback(Accept),null);
			return true;
		}
开发者ID:welterde,项目名称:obsidian,代码行数:8,代码来源:Listener.cs

示例14: BoggleServer

 /// <summary>
 /// #ctor
 /// makes server with new client lis
 /// </summary>
 /// <param name="port"></param>
 public BoggleServer(int port)
 {
     server = new TcpListener(IPAddress.Any,port);
     clients = new Queue<Tuple<StringSocket, string>>();
     currentGames = new HashSet<game>();
     server.Start();
     server.BeginAcceptSocket(ConnectionAccept, null);
 }
开发者ID:jiiehe,项目名称:cs3500,代码行数:13,代码来源:BoggleServer.cs

示例15: Start

 public void Start(int port)
 {
     if (RequestHandler == null)
         throw new InvalidOperationException("You must hook the RequestHandler delegate first.");
     _listener = new TcpListener(IPAddress.Any, port);
     _listener.Start(500);
     _listener.BeginAcceptSocket(OnAccept, null);
 }
开发者ID:Greeley,项目名称:Samples,代码行数:8,代码来源:HttpListener.cs


注:本文中的System.Net.Sockets.TcpListener.BeginAcceptSocket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。