server.cpp 745 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "socketio.hpp"
  2. #include <iostream>
  3. #include <exception>
  4. template<typename T>
  5. std::ostream& operator<<(std::ostream& out, std::vector<T> o){
  6. out << "(";
  7. for(unsigned int i = 0;i < o.size();i++){
  8. if(o[i] == '\r')continue;
  9. out << o[i];
  10. if(i < (o.size() - 1))
  11. out << ", ";
  12. }
  13. return out << ")";
  14. }
  15. template<>
  16. std::ostream& operator<< <char>(std::ostream& out, std::vector<char> o){
  17. for(unsigned int i = 0;i < o.size();i++){
  18. out << o[i];
  19. }
  20. return out;
  21. }
  22. int main(){
  23. server_socket ssock(80);
  24. while(true){
  25. cppsocket sock = ssock.accept_connection();
  26. try{
  27. std::vector<char> vec = sock.receive();
  28. sock.write("Hallo\n");
  29. sock.close();
  30. }
  31. catch(std::exception& e){
  32. std::cout << e.what() << std::endl;
  33. }
  34. }
  35. }