rendered paste body
m_mainSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, port);
// Bind to local IP Address...
m_mainSocket.Bind(ipLocal);
// Start listening...
m_mainSocket.Listen(4);
Func<IAsyncResult> accept = null;
accept = ( ar ) =>
{
var clientSocket = m_mainSocket.EndAccept(ar);
Socket workerSocket = m_mainSocket.EndAccept(asyn);
Client[m_clientCount] = new Player();
Client[m_clientCount].genSlots();
Client[m_clientCount].socket = workerSocket;
Client[m_clientCount].clientID = 0;
Client[m_clientCount].IP = Client[m_clientCount].socket.RemoteEndPoint.ToString();
String policyStr = "<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"8184\" /></cross-domain-policy>\0";
Client[m_clientCount].sendPolicy(policyStr);
Client[m_clientCount].policy = true;
Client[m_clientCount].Send("connected,");
Client[m_clientCount].threadID = m_clientCount;
appendLog("Client " + Client[m_clientCount].threadID + " has Connected!");
m_workerSocketList.Add(workerSocket);
UpdateClientListControl();
try
{
Func<IAsyncResult> receive() = null;
receive = (ar) =>
{
try
{
SocketPacket socketData = (SocketPacket)ar.AsyncState;
socketData.iRx = socketData.m_currentSocket.EndReceive(ar);
if (socketData.dataBuffer[0] != 0)
{
cq.Enqueue(socketData);
}
else
{
disconnectPlayer(socketData.m_clientNumber);
}
}
catch
{
}
try
{
Client[m_clientCount].socket.BeginReceive(dataBuffer, 0, dataBuffer.Length, SocketFlags.None, new AsyncCallback(receive), null);
}
catch
{
}
};
Client[m_clientCount].socket.BeginReceive(dataBuffer, 0, dataBuffer.Length, SocketFlags.None, new AsyncCallback(receive), null);
m_mainSocket.BeginAccept((new AsyncCallback(accept), null);
};
m_mainSocket.BeginAccept(new AsyncCallback(accept), null) ;