public static void InitClient() { // Initialize all Players //ToDO: Create InitPlayers(); //Initialize the packet list to listen to from server ClientHandleData.InitPacketsFromServer(); //Connect to the Server ClientTcp.ConnectClientToServer(Constants.SERVER_IP, Constants.PORT); }
private static void ReceiveCallback(IAsyncResult result) { try { int readByteSize = _clientNetworkStream.EndRead(result); if (readByteSize <= 0) { return; } byte[] newBytes = new byte[readByteSize]; Buffer.BlockCopy(_asyncBuffer, Constants.NETWORK_STREAM_OFFSET, newBytes, Constants.NETWORK_STREAM_OFFSET, readByteSize); ClientHandleData.HandleDataFromServer(newBytes); _clientNetworkStream?.BeginRead(_asyncBuffer, Constants.NETWORK_STREAM_OFFSET, Constants.MAX_BUFFER_SIZE * 2, ReceiveCallback, null); } catch { //todo: Write retry connection function ConnectClientToServer(Constants.SERVER_IP, Constants.PORT); } }