我正在尝试制作一个简单的邮件服务器来接收电子邮件并使用C ++中的套接字在屏幕上打印。我已经制作了这个程序,看起来很棒,但是不行。套接字和线程工作得很好,只需使用netcat或telnet登录就可以看到它有效,但是当我尝试向程序发送电子邮件时,没有任何反应。
我认为我在过程功能中做错了。看到......
void process(int new_sd, void *threadid) {
int tid = (long) threadid;
ssize_t bytes_recieved;
char incomming_data_buffer[1000];
while (1) {
bytes_recieved = recv(new_sd, incomming_data_buffer, 1000, 0);
// if (bytes_recieved == 0) cout << "host shut down." << endl ;
if (bytes_recieved == -1)cout << "Recieve Error! :(" << endl ;
incomming_data_buffer[bytes_recieved] = '\0';
trimwhitespace(incomming_data_buffer);
cout << "|" << incomming_data_buffer << "|" << endl;
if (!strcmp(incomming_data_buffer, "QUIT")) {
close(new_sd);
break;
} else {
send_text(new_sd, "OK \n");
}
}
}
完整的源代码在这里:http://pastebin.com/vLH8dSAj 要在Linux上编译:g ++ -lm mail.cpp -o mail
谢谢!