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 mSocket; private int mPort; #endregion #region Methods internal void Init(int Port) { this.mPort = Port; StartListen(); } internal void StartListen() { IPEndPoint Endpoint = new IPEndPoint(IPAddress.Any, mPort); mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); mSocket.Bind(Endpoint); mSocket.Listen(1000); mSocket.BeginAccept(new AsyncCallback(DataRequest), mSocket); } internal 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)"); } mSocket.BeginAccept(new AsyncCallback(DataRequest), mSocket); } #endregion } }