I'm having some problems with these two programs that seem to be unresponsive after a certain point:
Program 1:
#include <SFML/Network.hpp>
#include <iostream>
int main()
{
unsigned short Port;
sf::IpAddress Address1 = sf::IpAddress::GetPublicAddress();
sf::UdpSocket Socket;
char Buffer[] = "Hi guys!";
std::cin>>Port;
if (Socket.Send(Buffer, sizeof(Buffer), Address2, Port) != sf::Socket::Done)
{
std::cout<<"Socket (Send) Failed to Send"<<std::endl;
}
else if (Socket.Send(Buffer, sizeof(Buffer), Address1, Port) == sf::Socket::Done)
{
std::cout<<"Message sent"<<std::endl;
}
return 0;
}
Program 2:
#include <SFML/Network.hpp>
#include <iostream>
int main()
{
unsigned short Port;
sf::IpAddress Address1 = sf::IpAddress::GetPublicAddress();
std::cin>>Port;
sf::UdpSocket Listen;
if (Listen.Bind(Port) == sf::Socket::Done)
{
std::cout<<"Successfully bound to Port: "<<Port<<std::endl;
}
unsigned short portn = Listen.GetLocalPort();
std::size_t Received;
char Buffer2[128];
if (Listen.Receive(Buffer2, sizeof(Buffer2),Received,Address1,portn) != sf::Socket::Done)
{
std::cout<<"Error"<<std::endl;
}
else if (Listen.Receive(Buffer2, sizeof(Buffer2),Received,Address1,portn) == sf::Socket::Done)
{
std::cout<<"Message From:"<<std::endl;
std::cout<<Address1<<":"<<Listen.GetLocalPort()<<std::endl;
std::cout<<Buffer2<<std::endl;
}
else
std::cout<<"Unknown Problem";
return 0;
}
These are just snippings from the code, so if there's an error, it's probably me doing bad copy/pasting. Anyways, the send program seems to work fine, but the Listen program becomes unresponsive when it hits the .Receive...
So, what am I doing wrong?