Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - linkman2004

Pages: [1]
1
Network / UDP Message Receiving Woes
« on: July 11, 2010, 05:54:59 pm »
Well, crap... I'm a moron.  It works fine now.  Thanks for the help. :)

By the way, this is a nice little networking library; much easier than doing straight up Winsock, at the very least.

2
Network / UDP Message Receiving Woes
« on: July 11, 2010, 08:10:33 am »
I'm about to rip my hair out because of problems with my network, having spent the better part of my evening getting absolutely nowhere.  So, I have come here for help.

I'm currently working on a basic UDP client/server setup.  Clients send a message to the server, the server acknowledges them with a message of its own, everything is hunky dory... at least, that's the way it should be.  The client sends the message fine, the server receives it fine, but the client isn't receiving the server's message.  Nothing is erroring out, so I don't know where the problem is.

Server code:

Code: [Select]
///////////////////////////////////////////////////
// Server
///////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <SFML/network.hpp>

using namespace std;

int main()
{
// Socket
sf::SocketUDP mySock;

// Bind the socket
mySock.Bind(3333);

// Check for messages
char buffer[128];
size_t received;
sf::IPAddress sender;
unsigned short port;
if (mySock.Receive(buffer, sizeof(buffer), received, sender, port) == sf::Socket::Done())
{
// Check what the message says
string message = buffer;
if (message == "join")
{
// A client is attempting to join
cout << "A client is attempting to join" << endl;

// Send a reply to the sender of this message
char reply[] = "accepted";
mySock.Send(reply, sizeof(reply), sender, port);
}
}
return 0;
}


Client code:

Code: [Select]
///////////////////////////////////////////////////
// Client
///////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <SFML/network.hpp>

using namespace std;

int main()
{
// Socket
sf::SocketUDP mySock;

// Bind the socket
mySock.Bind(3333);

// Send a message to the server
char request[] = "join";
mySock.Send(request, sizeof(request), "127.0.0.1", 3333);

// Check for messages
char buffer[128];
size_t received;
sf::IPAddress sender;
unsigned short port;
if (mySock.Receive(buffer, sizeof(buffer), received, sender, port) == sf::Socket::Done())
{
// Check what the message says
string message = buffer;
if (message == "join")
{
// Accepted
cout << "Accepted" << endl;
}
}
return 0;
}


Note that I don't have access to my main computer at the moment, so this is as accurate a recreation of the code that I could create from memory.  I'll put up the real deal later if necessary.

I'd be really thankful if somebody could point me in the right direction with this. :)

Pages: [1]