Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Socket.h"
- // Link with ws2_32.lib
- #pragma comment(lib, "Ws2_32.lib")
- Socket::Socket()
- {
- listen_socket = INVALID_SOCKET;
- bound = false;
- }
- Socket::Socket(std::string IP_address_param, uint16_t port_param)
- {
- IP_address = IP_address_param;
- port = port_param;
- listen_socket = INVALID_SOCKET;
- bound = false;
- }
- Socket::~Socket()
- {
- }
- bool Socket::operator<(const Socket& other) const
- {
- if (IP_address < other.IP_address)
- true;
- if (IP_address > other.IP_address)
- return false;
- else // If they have same IP addresses
- {
- if (port < other.port)
- return true;
- else
- return false;
- }
- }
- bool Socket::operator==(const Socket& other) const
- {
- if (IP_address == other.IP_address)
- {
- if (port == other.port)
- return true;
- }
- return false;
- }
- std::ostream& operator<<(std::ostream& os, const Socket& sock)
- {
- os << sock.IP_address << ":" << sock.port;
- return os;
- }
- int Socket::close_socket()
- {
- int result = closesocket(listen_socket);
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement