Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL Message Framing #38

Closed
developervariety opened this issue Dec 27, 2019 · 3 comments
Closed

SSL Message Framing #38

developervariety opened this issue Dec 27, 2019 · 3 comments

Comments

@developervariety
Copy link

developervariety commented Dec 27, 2019

I'm experiencing an issue with my implementation of message framing. I've read the other issue (#3) and practically did the same thing, but the server tends to crash at random times.

This is the code from my server.

private void SendData(string json) {
 byte[] data = Serialization.GroBuf.Serialize(json);

 byte[] sizeInfo = new byte[4];
 sizeInfo[0] = (byte) data.Length;
 sizeInfo[1] = (byte)(data.Length >> 8);
 sizeInfo[2] = (byte)(data.Length >> 16);
 sizeInfo[3] = (byte)(data.Length >> 24);

 SendAsync(sizeInfo);
 SendAsync(data);
}

private long _totalRead;
private bool _receivingMessage;
private int _messageSize;
private byte[] _fullMessage;
protected override async void OnReceived(byte[] buffer, long offset, long size) {
 if (!_receivingMessage && size == 4) {
  _messageSize |= buffer[offset + 0];
  _messageSize |= buffer[offset + 1] << 8;
  _messageSize |= buffer[offset + 2] << 16;
  _messageSize |= buffer[offset + 3] << 24;
  _receivingMessage = true;
  _fullMessage = new byte[_messageSize];
 } else if (_messageSize != 0) {
  Array.Copy(buffer, offset, _fullMessage, _totalRead, size); // System.ArgumentException: Destination array was not long enough. Check the destination index, length, and the array's lower bounds. (Parameter 'destinationArray')
  _totalRead += size;
  if (_messageSize != _totalRead) return;

  await HandleData(_fullMessage);

  _fullMessage = null;
  _messageSize = 0;
  _receivingMessage = false;
  _totalRead = 0;
 }
}

Any help is appreciated, thank you.

@TailyFair
Copy link

How did you resolved this issue? Was issue in framework or in application code?

@developervariety
Copy link
Author

Hey @TailyFair, I'm sorry but I do not use this project anymore. I use WatsonTcp for all my needs, not to bash this amazing project.

@sojournercntl
Copy link

#117 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants