這讓我爬上了牆壁。我找不到爲什麼這個來源不打開一個套接字。這很簡單,但不起作用。有人可以幫助我嗎?感謝您的考慮!順便說一句:我沒有在屏幕上顯示文本,並使用BIO_do_accept()函數進行阻止。一些神祕不工作的OpenSSL源碼
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/x509v3.h>
#include <iostream>
#include <process.h>
using namespace std;
int main() {
SSL_load_error_strings();
SSL_library_init();
OpenSSL_add_all_algorithms();
BIO *abio, *cbio, *cbio2;
ERR_load_crypto_strings();
abio = BIO_new_accept("4444");
/* First call to BIO_accept() sets up accept BIO */
if(BIO_do_accept(abio) <= 0) {
fprintf(stderr, "Error setting up accept\n");
ERR_print_errors_fp(stderr);
exit(0);
}
/* Wait for incoming connection */
if(BIO_do_accept(abio) <= 0) {
fprintf(stderr, "Error accepting connection\n");
ERR_print_errors_fp(stderr);
exit(0);
}
fprintf(stderr, "Connection 1 established\n");
/* Retrieve BIO for connection */
cbio = BIO_pop(abio);
BIO_puts(cbio, "Connection 1: Sending out Data on initial connection\n");
fprintf(stderr, "Sent out data on connection 1\n");
}
你真的必須調用BIO_do_accept()兩次嗎? – Castilho 2012-04-02 09:38:36
是的,我不知道爲什麼,但是我做 – Confident 2012-04-02 09:40:22
所以,它阻止在BIO_do_accept()...哪裏的客戶端代碼連接到它? – 2012-04-03 09:11:05