Hi.
I am completly newbie in network programming, so got some problems in my project.
Here is some code.
Client:
if (socket.connect("127.0.0.1", 12312) != sf::Socket::Done)
{
cout << "ERROR1" << endl;
}
sf::Packet packetSend;
packetSend << "mapNameRequest";
if (socket.send(packetSend) != sf::Socket::Done)
{
cout << "ERROR2" << endl;
}
while (mapName == "")
{
sf::Packet packetReceive;
socket.receive(packetReceive);
packetReceive >> mapName;
}
//breakpoint
packetSend << "gameSessionNameRequest";
if (socket.send(packetSend) != sf::Socket::Done)
{
cout << "ERROR2" << endl;
}
while (gameSession.getGameSessionName() == "")
{
string msg;
sf::Packet packetReceive;
socket.receive(packetReceive);
packetReceive >> msg;
gameSession.setGameSessionName(msg);
}
Server:
listener.listen(PORT);
//Check requests
sf::Packet packetReceive;
string msg;
while(!quit)
{
if (listener.accept(socket) != sf::Socket::Done)
{
cout << "ERROR2" << endl;
}
if (socket.receive(packetReceive) != sf::Socket::Done)
{
cout << "ERROR3" << endl;
}
if (packetReceive >> msg)
{
if (msg == "mapNameRequest")
{
sf::Packet packetSend;
packetSend << gameMap;
if (socket.send(packetSend) != sf::Socket::Done)
{
cout << "ERROR4" << endl;
}
}
if (msg == "gameSessionNameRequest")
{
sf::Packet packetSend;
packetSend << gameSession.getGameSessionName();
if (socket.send(packetSend) != sf::Socket::Done)
{
cout << "ERROR4" << endl;
}
}
}
}
The problem is in client code. The first request is okay,client can receive mapName.
But after "//breakpoint" there are some porblems.
Client freezes at second "while" cycle. It cant receive "gameSessionNameRequest".
Sorry if question is too stupid.
Thanks.