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

Connection Message not reading back #65

Closed
CDCMacDaddy opened this issue Aug 24, 2022 · 1 comment
Closed

Connection Message not reading back #65

CDCMacDaddy opened this issue Aug 24, 2022 · 1 comment
Labels
User Error This issue was caused by user error

Comments

@CDCMacDaddy
Copy link

Hello - loving the framework so far. I'm having an issue with connection messages reading back properly. I get an error when getting parameters: "Message contains insufficient unread bytes (14) to read type 'string', result will be truncated!"

Here's an excerpt of what I'm doing on the client side:

private void StartClient()
{

client = new Client();
client.Connected += DidConnect;
client.ConnectionFailed += FailedToConnect;
client.Disconnected += ServerDidDisconnect;
var message = Message.Create(MessageSendMode.reliable, 5);
message.AddString("Test String");
Debug.Log($"Message {message.WrittenLength}");
client.Connect($"{ipAddress}:{messagePort}", 0, message );
clientRunning = true;

}

On the Server:

private void RemoteDidConnect(object sender, ServerClientConnectedEventArgs e)
{
Debug.Log("Remote Did Connect");
Debug.Log($"Unread: {e.ConnectMessage.UnreadLength}\n" +
$"{e.ConnectMessage.WrittenLength}");
var message = e.ConnectMessage;
Debug.Log($"Test string = {message.GetString()}");
}

Any ideas as to what I am doing incorrectly?
Thanks!

@tom-weiland
Copy link
Collaborator

This line right here is the problem:

var message = Message.Create(MessageSendMode.reliable, 5);

because it creates a message with a header and ID, both of which are then included in the actual connect message and considered part of the payload. The receiving end will then interpret those extra bytes as the bytes containing the length of the string, but that's obviously not what they are, so it ends up being completely incorrect. Then it tries to retrieve the string itself, but because it's expecting there to be more bytes than there actually are, you get that error.

The client.Connect method expects a message with nothing in it other than the data you want to send, and you can get an empty message instance like so:

var message = Message.Create();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
User Error This issue was caused by user error
Projects
None yet
Development

No branches or pull requests

2 participants