I create a peer to peer connection using a QosType.ReliableSequenced connection and start sending messages. Have no issues for the first 100 messages but then messages are dropped. When messages start getting dropped seems to be dependent on the size of the buffer being used for the connection; the larger the buffer the sooner the messages start getting dropped.
If I change to a QosType.AtAllCost connection, the messages start appearing out of order at the same place that the reliable connection starting dropping them, but they all do end up being transmitted.
This is my first post because I have been able to find answers or documentation to help me through all the issues I’ve hit before but I’ve been stuck on this issue for two weeks and I’m not able to find anything that helps me with this and I haven’t really made any progress in two weeks. Any help would be appreciated. The code below shows connection, sending, and receiving since I don’t know where I’m creating the issue.
public static bool Connect(string opponentIPaddr)
{
if (!channelEstablished)
{
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.ReactorModel = ReactorModel.SelectReactor;
globalConfig.ThreadAwakeTimeout = 10;
globalConfig.MaxPacketSize = 1500;
globalConfig.ReactorMaximumReceivedMessages = 2 * 128;
globalConfig.ReactorMaximumSentMessages = 2 * 128;
ConnectionConfig config = new ConnectionConfig();
config.AckDelay = 33;
config.AllCostTimeout = 20;
config.MaxCombinedReliableMessageCount = 10;
config.MaxCombinedReliableMessageSize = 100;
config.MaxSentMessageQueueSize = 128;
config.MinUpdateTimeout = 10;
config.NetworkDropThreshold = 5;
config.OverflowDropThreshold = 5;
config.PacketSize = 1500;
config.ResendTimeout = 1200;
reliableChannelId = config.AddChannel(QosType.ReliableSequenced);
int maxConnections = 2;
HostTopology topology = new HostTopology(config, maxConnections);
topology.ReceivedMessagePoolSize = 128;
topology.SentMessagePoolSize = 128;
NetworkTransport.Init(globalConfig);
serverSocket = NetworkTransport.AddHost(topology, socketPort);
clientSocket = NetworkTransport.AddHost(topology);
byte error;
connectionId = NetworkTransport.Connect(clientSocket, opponentIPaddr, socketPort, 0, out error);
if (connectionId <= 0)
return (false);
else
return (true);
}
return (true); // Connection already established
}
public static void SendSocketMessage(string message)
{
if (connectionConfirmed)
{
Stream stream = new MemoryStream(sendBuffer);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, message);
if (MainMenuRoutines.userIsIntiating)
NetworkTransport.Send(serverSocket, connectionId, reliableChannelId, sendBuffer, BUFFERSIZE, out sendError);
else
NetworkTransport.Send(clientSocket, connectionId, reliableChannelId, sendBuffer, BUFFERSIZE, out sendError);
}
}
}
void Update()
{
// This is what sends the messages. This is just a test message.
if (!GlobalDefinitions.gameStarted)
{
if (handshakeConfirmed && opponentComputerConfirmsSync)
{
GlobalDefinitions.gameStarted = true;
// This is a test to try to see what is causing messages to be dropped
int messageSize = 1;
int numberOfMessages = 1000;
string testMessage = "A";
for (int a = 1; a < messageSize; a++)
testMessage = testMessage + "A";
for (int index = 1; index < numberOfMessages; index++)
SendSocketMessage("INDEX " + index + " " + testMessage);
}
}
// This is what's receiving the messages
else if (!GlobalDefinitions.localControl && (GlobalDefinitions.GameMode == GlobalDefinitions.GameModeValues.Network))
{
int recHostId;
int recConnectionId;
int recChannelId;
byte[] recBuffer = new byte[TransportScript.BUFFERSIZE];
int bufferSize = TransportScript.BUFFERSIZE;
int dataSize;
byte error;
NetworkEventType recNetworkEvent = NetworkTransport.Receive(out recHostId, out recConnectionId, out recChannelId, recBuffer, bufferSize, out dataSize, out error);
switch (recNetworkEvent)
{
case NetworkEventType.DataEvent:
Stream stream = new MemoryStream(recBuffer);
BinaryFormatter formatter = new BinaryFormatter();
string message = formatter.Deserialize(stream) as string;
TransportScript.OnData(recHostId, recConnectionId, recChannelId, message, dataSize, (NetworkError)error); // This is just writing to a log file
break;
default:
break;
}
}
}