包含的lib库文件,免得一个一个复制名称:
sfml-window-d.lib
sfml-system-d.lib
sfml-audio-d.lib
sfml-graphics-d.lib
sfml-main-d.lib
sfml-network-d.lib
vorbis.lib
vorbisenc.lib
vorbisfile.lib
void runUdpClient(unsigned short port)
{
// Ask for the server address
sf::IpAddress server;
do
{
std::cout << "Type the address or name of the server to connect to: ";
std::cin >> server;
} while (server == sf::IpAddress::None);
// Create a socket for communicating with the server
sf::UdpSocket socket;
// Send a message to the server
const char out[] = "Hi, I'm a client";
if (socket.send(out, sizeof(out), server, port) != sf::Socket::Done)
return;
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
// Receive an answer from anyone (but most likely from the server)
char in[128];
std::size_t received;
sf::IpAddress sender;
unsigned short senderPort;
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
{
return;
}
std::cout << "Message received from " << sender << ": \"" << in << "\"" << std::endl;
}
using namespace sf;
void runUdpPackageClient()
{
// Ask for the server address
IpAddress adress("localhost");
// Create a socket for communicating with the server
sf::UdpSocket socket;
Packet sendpacket;
sendpacket << "ceshishuju";
socket.send(sendpacket, adress, 1028);
IpAddress remoteAddress;
unsigned short remotePort;
Packet packet;
if (socket.receive(packet, remoteAddress, remotePort) != sf::Socket::Done)
{
return;
}
int yyyy = 666;
}
测试使用SocketTool.exe工具即可