I could receive packets and send them but the SFML window just freezes.
#ifdef _WIN32
//#include <windows.h>
#endif
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Network.hpp>
#include <sys/timeb.h>
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <fstream>
using namespace std;
sf::Clock Clock;
sf::RenderWindow App;
float CurTime( void )
{
return Clock.GetElapsedTime();
}
void Initialize();
void Draw();
void Think();
void KeyPress(sf::Key::Code Key);
void KeyReleased(sf::Key::Code Key);
void OnRecieve(const char* Message);
float NextThink = 0;
sf::SocketTCP Client;
int main()
{
App.Create(sf::VideoMode(640, 480), "MMOClient v0.1");
ifstream ipfile("ip.txt",ios::in);
sf::IPAddress ServerAddress;
ipfile >> ServerAddress;
ipfile.close();
const unsigned short Port = 2435;
if (Client.Connect(Port,ServerAddress) == sf::Socket::Done)
{
std::cout << "Connected to server " << ServerAddress << std::endl;
} else {
App.Close();
}
//Initialize();
bool isrunning = true;
while (isrunning)
{
sf::Packet p;
std::string s;
if (Client.Receive(p) == sf::Socket::Done)
{
p >> s;
std::cout << s << std::endl;
}
char ToSend[] = "w-off";
Client.Send(ToSend, sizeof(ToSend));
App.Clear();
Draw();
App.Display();
}
/*while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if (Event.Type == sf::Event::KeyPressed)
KeyPress(Event.Key.Code);
if (Event.Type == sf::Event::KeyReleased)
KeyReleased(Event.Key.Code);
}
//if (Client.Receive(Message, sizeof(Message), Received))
//{
//OnRecieve(Message);
//}
if (NextThink < CurTime())
{
NextThink = CurTime() + 0.02;
Think();
}
App.Clear();
Draw();
App.Display();
}*/
Client.Close();
return EXIT_SUCCESS;
}