心血来潮,简单实现一个发送邮件的小程序,
首先实现一个简单的socket类
头文件
#ifndef _CSOCKET_H_
#define _CSOCKET_H_
#include <sys/socket.h>
#include <arpa/inet.h>
#define BUFF_LEN 256
class CSocket
{
public:
CSocket();
~CSocket();
bool initialize(const char* ip, const int port);
bool sendSocketMessage(const char* mesg);
bool reviceSocketMessage();
char* getReviceMessage();
private:
int m_sockfd;
char m_reciveBuff[BUFF_LEN];
struct sockaddr_in m_add;
};
#endif //_CSOCKET_H_
类的实现
#include <unistd.h>
#include <string.h>
#include <memory.h>
#include <iostream>
#include "CSocket.h"
using namespace std;
CSocket::CSocket()
:m_sockfd(-1)
{
}
CSocket::~CSocket()
{
if(-1 != m_sockfd)
{
close(m_sockfd);
}
}
bool CSocket::initialize(const char* ip, const int port)
{
m_sockfd = socket(AF_INET, SOCK_S