Okay so I tried to create some small app to send and one to recieve small messages, but I'm not sure the client sends the message. :?
server.cpp
#include <SFML/Network.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
sf::Mutex GlobalMutex;
bool ThreadRunning = true;
void ServerPoll(void* UserData)
{
GlobalMutex.Lock();
std::cout << "Starting up Server." << std::endl;
GlobalMutex.Unlock();
sf::SocketUDP Server;
Server.Bind(6739);
sf::IPAddress ip(127,0,0,1);
GlobalMutex.Lock();
std::cout << "Finished setting up for Thread." << std::endl;
GlobalMutex.Unlock();
while(ThreadRunning)
{
char Message[128];
std::size_t Received;
GlobalMutex.Lock();
std::cout << "Waiting for message." << std::endl;
GlobalMutex.Unlock();
if(!Server.Receive(Message, sizeof(Message), Received, ip));
return;
GlobalMutex.Lock();
std::cout << "Message recieved." << std::endl;
GlobalMutex.Unlock();
GlobalMutex.Lock();
std::cout << Message << std::endl;
GlobalMutex.Unlock();
}
GlobalMutex.Lock();
std::cout << "Finished thread." << std::endl;
GlobalMutex.Unlock();
GlobalMutex.Lock();
std::cout << "Closing server." << std::endl;
GlobalMutex.Unlock();
Server.Close();
GlobalMutex.Lock();
std::cout << "Closed server." << std::endl;
GlobalMutex.Unlock();
}
int main()
{
sf::RenderWindow App(sf::VideoMode(800,600), "Target lul");
sf::Thread Thread(&ServerPoll);
bool Running = true;
bool ThreadRunning = true;
Thread.Launch();
while(Running)
{
sf::Event Event;
if(App.GetEvent(Event))
{
if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Escape)
{
Running = false;
ThreadRunning = false;
}
}
App.Display();
}
return 0;
}
client.cpp
#include <SFML/Network.hpp>
#include <iostream>
int main()
{
sf::IPAddress target(127,0,0,1);
unsigned short port = 6739;
sf::SocketUDP Client;
Client.Bind(port);
char Buffer[] = "HEYAHO :D:DDd.Dd:D";
std::cout << "Sending message: " << Buffer << std::endl;
if (!Client.Send(Buffer, sizeof(Buffer), target, port))
{
std::cout << "Msg fail" << std::endl;
return 0;
}
Client.Close();
std::cout << "Finished." << std::endl;
return EXIT_SUCCESS;
}
Any ideas? The output I get from client.cpp is "Msg fail", so I guess I might have some parameters wrong.