Hi,
I have some troubles when I try to send big packet with TCP.
When packets are too big, sending status become sf::Status::Not_Ready regardless on how much time I sleep the program.
When the server have problem, the receiving status of the client still sf::Status::Done and I receive the same packet indefinitely.
I already post a topic on the SFML French forum here-->
http://fr.sfml-dev.org/forums/index.php?topic=12537Laurent advise me to ask it on the English forum.
Some details:- I use SFML 2.1
- I use not blocking sockets ( everything work with blocking sockets)
- I use the localhost (127.0.0.1) and 2 instances of my applications to test.
- I use Linux (Lubuntu)
I have done a minimal code that reproduce this problem:
The serveur sends packets. Packets grow up by multipling its size by 2 each time.
If the sending status is NotReady, the program sleep during a time which is multiplied by 2 each time.
The client receives each packets.
#include <SFML/Network.hpp>
#include <iostream>
void sendBigPaquet(int size, sf::TcpSocket& socket, int timeout=1)
{
std::cout<<"sending paquet size="<<size;
sf::Packet paquet;
paquet<<sf::Uint32(size);
for(int i=0;i<size;++i)
{
paquet<<sf::Uint32(0);
}
switch (socket.send(paquet))
{
case sf::Socket::Done:
std::cout<<" Status : Done"<<std::endl;
break;
case sf::Socket::NotReady:
std::cout<<" Status : NotReady"<<std::endl;
std::cout<<"waiting "<<timeout<<" secondes"<<std::endl;
sf::sleep(sf::seconds(timeout));
sendBigPaquet(size,socket,timeout*2);
break;
case sf::Socket::Disconnected:
std::cout<<" Status : Diconnected"<<std::endl;
break;
case sf::Socket::Error:
std::cout<<" Status : Error"<<std::endl;
break;
}
}
void receiveBigPaquet(sf::TcpSocket& socket)
{
sf::Packet paquet;
switch (socket.receive(paquet))
{
case sf::Socket::Done:
std::cout<<"Status : Done ";
sf::Uint32 size;
paquet>>size;
std::cout<<"receiving paquet size = " << int(size)<<std::endl;
//for(int i=0;i<int(size);++i)
//{
//sf::Uint32 b;
//paquet>>b;
//}
break;
case sf::Socket::NotReady:
std::cout<<"Status : Not ready"<<std::endl;
break;
case sf::Socket::Disconnected:
std::cout<<"Status : Disconnected"<<std::endl;
break;
case sf::Socket::Error:
std::cout<<"Status : Error"<<std::endl;
break;
}
}
int main(int argc, const char *argv[])
{
std::cout<<"server(0) ou client(1)"<<std::endl;
int server;
std::cin>>server;
std::cout<<"port:"<<std::endl;
int port;
std::cin>>port;
if (server==0)
{
// Server
sf::TcpListener serverListener;
sf::TcpSocket socket;
socket.setBlocking(false);
serverListener.setBlocking(false);
serverListener.listen(port);
while (serverListener.accept(socket)!=sf::Socket::Done)
sf::sleep(sf::seconds(0.3));
int size=1;
for(;;)
{
sendBigPaquet(size,socket);
sf::sleep(sf::seconds(1.0));
size*=2;
}
}
else
{
// client
sf::TcpSocket socket;
socket.setBlocking(false);
while(socket.connect("127.0.0.1",port)!=sf::Socket::Done)
sf::sleep(sf::seconds(0.3));
for(;;)
{
receiveBigPaquet(socket);
sf::sleep(sf::seconds(0.3));
}
}
return 0;
}
And that is what I get for the server
./main
server(0) ou client(1)
0
port:
2222
sending paquet size=1 Status : Done
sending paquet size=2 Status : Done
sending paquet size=4 Status : Done
sending paquet size=8 Status : Done
sending paquet size=16 Status : Done
sending paquet size=32 Status : Done
sending paquet size=64 Status : Done
sending paquet size=128 Status : Done
sending paquet size=256 Status : Done
sending paquet size=512 Status : Done
sending paquet size=1024 Status : Done
sending paquet size=2048 Status : Done
sending paquet size=4096 Status : Done
sending paquet size=8192 Status : Done
sending paquet size=16384 Status : Done
sending paquet size=32768 Status : Done
sending paquet size=65536 Status : Done
sending paquet size=131072 Status : Done
sending paquet size=262144 Status : Done
sending paquet size=524288 Status : Done
sending paquet size=1048576 Status : NotReady
waiting 1 secondes
sending paquet size=1048576 Status : NotReady
waiting 2 secondes
sending paquet size=1048576 Status : NotReady
waiting 4 secondes
sending paquet size=1048576 Status : NotReady
waiting 8 secondes
And for the client
./main
server(0) ou client(1)
1
port:
2222
Status : Done receiving paquet size = 1
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 2
Status : Not ready
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 4
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 8
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 16
Status : Not ready
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 32
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 64
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 128
Status : Not ready
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 256
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 512
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 1024
Status : Not ready
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 2048
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 4096
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 8192
Status : Not ready
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 16384
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 32768
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 65536
Status : Not ready
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 131072
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 262144
Status : Not ready
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 524288
Status : Not ready
Status : Not ready
Status : Not ready
Status : Not ready
Status : Not ready
Status : Not ready
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Status : Done receiving paquet size = 1048576
Anybody has an idea ?
Thanks.