Advertisement
RoshHoul

Untitled

Jan 4th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1.  
  2. sf::RenderWindow window(sf::VideoMode(504, 504), "Server");
  3. sf::Event e;
  4.  
  5. sf::IpAddress ip = sf::IpAddress::getLocalAddress();
  6. sf::TcpSocket socket;
  7. int port = 2000;
  8. sf::Int32 sending[8][8], recieving[8][8];
  9.  
  10. sf::TcpListener listener;
  11.  
  12. socket.setBlocking(false);
  13. if (listener.listen(port) != sf::Socket::Done) {
  14. std::cout << "Check if port is free" << endl;
  15. exit(EXIT_FAILURE);
  16. }
  17.  
  18. if (listener.accept(socket) != sf::Socket::Done) {
  19. std::cout << "Error accepting socket" << endl;
  20. exit(EXIT_FAILURE);
  21. }
  22.  
  23. while (window.isOpen()) {
  24. if (socket.getRemotePort() == 0) {
  25. cout << "Client Disconnected" << endl;
  26. }
  27. else {
  28. cout << "client connected" << endl;
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement