Socket封装6
来源:互联网 发布:mdf数据格式文件 编辑:程序博客网 时间:2024/06/01 08:52
#ifndef SOCK_SERVERSOCKET_H
#define SOCK_SERVERSOCKET_H
// #include <standard library headers>
// #include <other library headers>
// #include "customer headers"
#include "Socket.h"
namespace sock
{
class ServerSocket : public Socket
{
public:
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() {}
virtual ~ServerSocket() {}
public:
const ServerSocket& operator << (const std::string& s) const
{
if (!Socket::Send(s))
{
throw SocketException ( "Could not write to socket." );
}
return *this;
}
const ServerSocket& operator >> (std::string& s) const
{
if (Socket::Recv(s) < 0)
{
throw SocketException("Could not read from socket.");
}
return *this;
}
void Accept(ServerSocket& sock, int sec = -1, int usec = -1)
{
if (!Socket::Accept(sock, sec, usec))
{
throw SocketException("Could not accept socket.");
}
}
};
}
#endif // SOCK_SERVERSOCKET_H
- Socket封装6
- Socket封装
- 自己封装socket
- 事件模型SOCKET封装
- Socket封装2
- Socket封装3
- Socket封装4
- Socket封装5
- Socket封装7
- Socket封装7
- Socket封装8
- Socket封装9
- Socket封装10
- Socket封装11
- Socket封装12
- 跨平台Socket封装
- 跨平台Socket封装
- linux socket 函数封装
- H.264 视频 RTP 负载格式
- Socket封装4
- 几个实用的软件开发工具之——代码检测工具
- Socket封装5
- 几个实用的软件开发工具之——性能优化工具
- Socket封装6
- Socket封装7
- 一名25岁的董事长给大学生的忠告
- Socket封装7
- reactos操作系统实现(89)
- 9.18 项目第一,是必然,今天还是很开心的
- 最有用的八个cmd网络命令
- POJ 8道简单的并查集 秒光了所有已知的简单并查集,总结一下,共8道。
- 几个实用的软件开发工具之——版本管理工具