serversocket.cpp
来自「这是书上的代码」· C++ 代码 · 共 60 行
CPP
60 行
// Implementation of the ServerSocket class#include "ServerSocket.h"#include "SocketException.h"ServerSocket::ServerSocket ( int port ){ if ( ! Socket::create() ) { throw SocketException ( "Could not create server socket." ); } if ( ! Socket::bind ( port ) ) { throw SocketException ( "Could not bind to port." ); } if ( ! Socket::listen() ) { throw SocketException ( "Could not listen to socket." ); }}ServerSocket::~ServerSocket(){}const ServerSocket& ServerSocket::operator << ( const std::string& s ) const{ if ( ! Socket::send ( s ) ) { throw SocketException ( "Could not write to socket." ); } return *this;}const ServerSocket& ServerSocket::operator >> ( std::string& s ) const{ if ( ! Socket::recv ( s ) ) { throw SocketException ( "Could not read from socket." ); } return *this;}void ServerSocket::accept ( ServerSocket& sock ){ if ( ! Socket::accept ( sock ) ) { throw SocketException ( "Could not accept socket." ); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?