Hi!
Sorry for my English!
I have C# AsyncServer. It sends packages to Unity client. Unity client has ClientSocket : MonoBehaviour on scene. SocketController receives packages quite well, but sometimes Unity (ClientSocket) does not receive some server packages (no errors in package receiving in parsing -100%).
Antivirus switched on/off.
Port is allowed.
Changed send package delay time on server (from 1 to 200 ms).
No error! No warnings (there are my debug warnings)! Nothing! Silence - just no packages!
Socket Receiving Method:
private Socket _clientSocket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp
);
private byte[] _recieveBuffer = new byte[32768];
private void ReceiveCallback(IAsyncResult ar) {
int recieved = _clientSocket.EndReceive(ar);
byte[] recData = new byte[recieved];
Buffer.BlockCopy(
_recieveBuffer,
0,
recData,
0,
recieved
);
Receive();
}
private void Receive() {
_clientSocket.BeginReceive(
_recieveBuffer,
0,
_recieveBuffer.Length,
SocketFlags.None,
new AsyncCallback(ReceiveCallback),
_clientSocket
);
}
This is very annoying situation, because Unity reports nothing! I do not know what to do. Should I use Socket.ReceiveAsync(SocketAsyncEventArgs) or other methods? I would like to find out what’s happening.
Thanks!