1
Network / Cannot receive when sending to myself
« on: July 02, 2011, 12:24:20 am »
I'm completely new to Networking, and have been attempting to send myself UDP packets, but I'm just not receiving them.
Sending to 127.0.0.1
gets to binding socket but cannot receive.
I have done it both with and without port forwarding (I assumed it wouldn't make a difference, but tried anyway).
Any help would be greatly appreciated!
Sending to 127.0.0.1
gets to binding socket but cannot receive.
I have done it both with and without port forwarding (I assumed it wouldn't make a difference, but tried anyway).
Code: [Select]
int main ()
{
sf::IPAddress mycomp("127.0.0.1");
sf::SocketUDP mycompSocket;
char buffer[] = "hello computer";
std::cout << "sending data" << std::endl;
if (mycompSocket.Send( buffer, sizeof(buffer), sf::IPAddress::LocalHost, 4567) != sf::Socket::Done)
{
std::cout << "error sending" << std::endl;
}
std::cout << "data sent" << std::endl;
sf::SocketUDP receiver;
char thingo[128] = "";
std::size_t receivedsize;
sf::IPAddress sender;
unsigned short port;
receiver.SetBlocking(false);
if (!receiver.Bind(4567))
{
std::cout << "could not bind socket" << std::endl;
}
std::cout << "port boundedededed: " << receiver.GetPort() << std::endl;
std::cout << "socket bound" << std::endl;
if (receiver.Receive(thingo, sizeof(thingo), receivedsize, sender, port) != sf::Socket::Done)
{
std::cout << "could not receive" << std::endl;
}
std::cout << "the IP Address: " << sender << std::endl;
std::cout << "received: " << thingo << std::endl;
mycompSocket.Close();
receiver.Close();
}
Any help would be greatly appreciated!