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

fix: KcpServer.Start return when server is started #42

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions kcp2k/Assets/Tests/Editor/ClientServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public void ClientToServerTooLargeReliableMessage()
byte[] message = new byte[KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize) + 1];

#if UNITY_2018_3_OR_NEWER
UnityEngine.TestTools.LogAssert.Expect(UnityEngine.LogType.Error, new Regex($".*Failed to send reliable message of size {message.Length} because it's larger than ReliableMaxMessageSize={KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize)}"));
UnityEngine.TestTools.LogAssert.Expect(UnityEngine.LogType.Warning, new Regex($".*Failed to send reliable message of size {message.Length} because it's larger than ReliableMaxMessageSize={KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize)}"));
#endif
SendClientToServerBlocking(new ArraySegment<byte>(message), KcpChannel.Reliable);
Assert.That(serverReceived.Count, Is.EqualTo(0));
Expand Down Expand Up @@ -660,7 +660,7 @@ public void ServerToClientTooLargeReliableMessage()

byte[] message = new byte[KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize) + 1];
#if UNITY_2018_3_OR_NEWER
UnityEngine.TestTools.LogAssert.Expect(UnityEngine.LogType.Error, new Regex($".*Failed to send reliable message of size {message.Length} because it's larger than ReliableMaxMessageSize={KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize)}"));
UnityEngine.TestTools.LogAssert.Expect(UnityEngine.LogType.Warning, new Regex($".*Failed to send reliable message of size {message.Length} because it's larger than ReliableMaxMessageSize={KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize)}"));
#endif
SendServerToClientBlocking(connectionId, new ArraySegment<byte>(message), KcpChannel.Reliable);
Assert.That(clientReceived.Count, Is.EqualTo(0));
Expand All @@ -677,7 +677,7 @@ public void ServerToClientTooLargeUnreliableMessage()
byte[] message = new byte[KcpConnection.UnreliableMaxMessageSize + 1];

#if UNITY_2018_3_OR_NEWER
UnityEngine.TestTools.LogAssert.Expect(UnityEngine.LogType.Error, new Regex($".*Failed to send unreliable message of size {message.Length} because it's larger than UnreliableMaxMessageSize={KcpConnection.UnreliableMaxMessageSize}"));
UnityEngine.TestTools.LogAssert.Expect(UnityEngine.LogType.Warning, new Regex($".*Failed to send unreliable message of size {message.Length} because it's larger than UnreliableMaxMessageSize={KcpConnection.UnreliableMaxMessageSize}"));
#endif
SendServerToClientBlocking(connectionId, new ArraySegment<byte>(message), KcpChannel.Unreliable);
Assert.That(clientReceived.Count, Is.EqualTo(0));
Expand Down
10 changes: 5 additions & 5 deletions kcp2k/Assets/kcp2k/highlevel/KcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void TickIncoming_Connected(uint time)
// we were waiting for a handshake.
// it proves that the other end speaks our protocol.
// GetType() shows Server/ClientConn instead of just Connection.
Log.Info("${GetType()}: received handshake");
Log.Info($"{GetType()}: received handshake");
state = KcpState.Authenticated;
OnAuthenticated?.Invoke();
break;
Expand Down Expand Up @@ -578,12 +578,12 @@ void SendReliable(KcpHeader header, ArraySegment<byte> content)
if (sent < 0)
{
// GetType() shows Server/ClientConn instead of just Connection.
Log.Warning($"{GetType()}: Send failed with error={sent} for content with length={content.Count}");
OnError(ErrorCode.InvalidSend, $"{GetType()}: Send failed with error={sent} for content with length={content.Count}");
}
}
// otherwise content is larger than MaxMessageSize. let user know!
// GetType() shows Server/ClientConn instead of just Connection.
else Log.Error($"{GetType()}: Failed to send reliable message of size {content.Count} because it's larger than ReliableMaxMessageSize={ReliableMaxMessageSize(kcp.rcv_wnd)}");
// GetType() shows Server/ClientConn instead of just Connection.
else OnError(ErrorCode.InvalidSend, $"{GetType()}: Failed to send reliable message of size {content.Count} because it's larger than ReliableMaxMessageSize={ReliableMaxMessageSize(kcp.rcv_wnd)}");
}

void SendUnreliable(ArraySegment<byte> message)
Expand All @@ -610,7 +610,7 @@ void SendUnreliable(ArraySegment<byte> message)
public void SendHandshake()
{
// GetType() shows Server/ClientConn instead of just Connection.
Log.Info("${GetType()}: sending Handshake to other end!");
Log.Info($"{GetType()}: sending Handshake to other end!");
SendReliable(KcpHeader.Handshake, default);
}

Expand Down
1 change: 1 addition & 0 deletions kcp2k/Assets/kcp2k/highlevel/KcpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public void Start(ushort port)
if (socket != null)
{
Log.Warning("KCP: server already started!");
return;
}

// listen
Expand Down