private bool ReadConnectionPreamble(Socket socket, out GrainId grainId) { grainId = null; byte[] buffer = null; try { buffer = ReadFromSocket(socket, sizeof(int)); // Read the size if (buffer == null) { return(false); } Int32 size = BitConverter.ToInt32(buffer, 0); if (size > 0) { buffer = ReadFromSocket(socket, size); // Receive the client ID if (buffer == null) { return(false); } grainId = GrainId.FromByteArray(buffer); } return(true); } catch (Exception exc) { Log.Error(ErrorCode.GatewayFailedToParse, String.Format("Failed to convert the data that read from the socket. buffer = {0}, from endpoint {1}.", Utils.EnumerableToString(buffer), socket.RemoteEndPoint), exc); return(false); } }