# #include "ServerSocket.h"
#
# /*
# * 服务端Socket类
# */
#
# ServerSocket::ServerSocket(){
#
# }
#
# ServerSocket::~ServerSocket(){
#
# Close();
#
# }
#
# int ServerSocket::Socket(int type){
#
# sockfd = socket(AF_INET, type, 0);
# return sockfd;
#
# }
#
# void ServerSocket::SetPort(unsigned short in_port){
#
# my_addr.sin_family = AF_INET;
# port = in_port;
# my_addr.sin_port = htons(port);
# my_addr.sin_addr.s_addr = INADDR_ANY;
#
# }
#
# void ServerSocket::SetRemotePort(unsigned short in_port){
#
# their_addr.sin_port=htons(in_port);
#
# }
#
# unsigned short ServerSocket::GetRemotePort(){
#
# return ntohs(get_addr.sin_port);
#
# }
#
# bool ServerSocket::Bind(){
#
# if(bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr))==-1)
# return false;
#
# return true;
#
# }
#
# int ServerSocket::Recvfrom(char *buf,int len){
#
# int numbytes;
# socklen_t addr_len = sizeof(get_addr);
# numbytes = recvfrom(sockfd,buf,len,0,(struct sockaddr *)&get_addr,&addr_len);
# if(numbytes == -1)
# {
# return false;
# }
# buf[numbytes] = '\0';
#
# return numbytes;
#
# }
#
# int ServerSocket::Sendto(const char *buf,int len){
#
# return sendto(sockfd,buf,len,0,(struct sockaddr *)&their_addr,sizeof(struct sockaddr));
#
# }
#
# bool ServerSocket::SetRemoteAddrees(const char* addrees){
#
#
# struct hostent *he;
# if((he = gethostbyname(addrees)) == NULL)
# return false;
#
# their_addr.sin_family = AF_INET;
# their_addr.sin_port = htons(port);
# their_addr.sin_addr = *((struct in_addr *)he->h_addr);
#
# return true;
#
# }
#
# void ServerSocket::GetRemoteAddrees(char *addrees){
#
# strcpy(addrees,inet_ntoa(get_addr.sin_addr));
# SetRemoteAddrees(addrees);
# }
#
# void ServerSocket::Close(){
#
# close(sockfd);
# close(new_fd);
#
# }
#
# void ServerSocket::Listen(){
#
# listen(sockfd,10);
#
# }
#
# void ServerSocket::Accept(){
#
# socklen_t size = sizeof(struct sockaddr_in);
# new_fd = accept(sockfd,(struct sockaddr *)&get_addr,&size);
#
# }
#
# int ServerSocket::Recv(char *buf,int len){
#
# return recv(new_fd,buf,len,0);
#
# }
#
# int ServerSocket::Send(const char *buf, int len){
#
# return send(sockfd,buf,len,0);
#
# }
#
# bool ServerSocket::Connect(){
#
# if(connect(sockfd,(struct sockaddr *)&their_addr, sizeof(struct sockaddr))==-1)
# return false;
#
# return true;
#
# }
|