1
Network / Re: Looping through clients with TCP selector
« on: March 26, 2012, 01:52:00 pm »
Okay, then it makes sense that I didn't find anything (:
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.
#include <SFML/Network.hpp>
#include <iostream>
void Receive();
sf::SocketUDP Socket;
int main()
{
std::cout << "Send or receive (0/1): ";
int choice;
std::cin >> choice;
if (choice == 1)
{
Socket.Bind(4639);
Socket.SetBlocking(false);
while (true)
{
Receive();
}
}
else
{
while (true)
{
sf::Packet Packet;
Packet << 1;
Socket.Send(Packet, "localhost", 4639);
}
}
return EXIT_SUCCESS;
}
void Receive()
{
sf::Packet Packet;
sf::IPAddress IP;
unsigned short port;
Socket.Receive(Packet, IP, port);
if (IP != "255.255.255.255")
{
int PType = -1;
Packet >> PType;
if (PType == -1)
{
std::cout << "Bad Packet!" << std::endl;
}
std::cout << "Packet received! IP: " << IP << " Port: " << port << " Packet Type: " << PType << std::endl;
}
}
sf::Packet Packet;
sf::IPAddress IP;
unsigned short Port;
std::cout << "Waiting for clients..." << std::endl;
Socket.Receive(Packet, IP, Port);
std::cout << "Connection received!" << std::endl;
int Type;
if (Packet >> Type == 1)
{
std::string userName, Password;
Packet >> userName >> Password;
std::cout << "Username: " << userName << " Password: " << Password << std::endl;
}
sf::SocketUDP UDP;
sf::Packet testPacket;
int Type = 1;
std::string userName = "00";
std::string password = "00";
std::cout << "Enter username: ";
std::getline(std::cin, userName);
std::cout << "Enter password: ";
std::getline(std::cin, password);
sf::IPAddress Address = "127.0.0.1";
unsigned short portNr = 4639;
testPacket << Type << userName << password;
UDP.Send(testPacket, Address, portNr);
std::cout << "Sent Login to " << Address << ":" << portNr << std::endl;
1>------ Build started: Project: SFML-Test, Configuration: Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::Window::~Window(void)" (__imp_??1Window@sf@@UAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::Display(void)" (__imp_?Display@Window@sf@@QAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Window::Window(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::WindowSettings const &)" (__imp_??0Window@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUWindowSettings@1@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function _main
1>E:\C++\SFML-Test\Debug\SFML-Test.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#include <SFML/Window.hpp>
int main()
{
sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");
bool Running = true;
while (Running)
{
App.Display();
}
return EXIT_SUCCESS;
}