using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Sockets; using System.Collections; using System.Net; namespace Chop { public class GameSocket { #region Declares private Socket _socket; private readonly int _port; #endregion public GameSocket(int port) { _port = port; } #region Methods public void Init() { StartListen(); } public void StartListen() { IPEndPoint Endpoint = new IPEndPoint(IPAddress.Any, _port); _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _socket.Bind(Endpoint); _socket.Listen(22); _socket.BeginAccept(new AsyncCallback(DataRequest), _socket); } public void DataRequest(IAsyncResult iAr) { try { Core.ClientManager.AddClient(((Socket)iAr.AsyncState).EndAccept(iAr)); } catch (SocketException) // Nothing special { } catch (ObjectDisposedException) // Nothing special { } catch (Exception x) { Console.WriteLine(x.ToString() + " (GameSocket.DataRequest)"); } _socket.BeginAccept(new AsyncCallback(DataRequest), _socket); } #endregion } }