前言服務器
以前在第四課實現了服務器加入組播,通知其餘客戶端服務器的IP地址和服務信息。本節課是綁定本地的端口,接收處理Onvif協議的報文socket
代碼tcp
//監聽soap報文
DWORD WINAPI OnvifWebServices(LPVOID p)
{ide
struct soap tcpSoap = { 0 };
soap_init(&tcpSoap);
//默認狀況下是TCP模式
tcpSoap.port = 80;
tcpSoap.bind_flags = SO_REUSEADDR;
//tcpSoap.accept_timeout = tcpSoap.recv_timeout = tcpSoap.send_timeout = 5;
soap_set_namespaces(&tcpSoap, namespaces);spa
SOAP_SOCKET localSocket = SoapBind(&tcpSoap, ONVIF_TCP_IP, false);
if (!soap_valid_socket(localSocket)) {
printf("tcpsocket SoapBind failed!\n");
soap_print_fault(&tcpSoap, stderr);
exit(1);
}ip
SOAP_SOCKET clientSocket = SOAP_INVALID_SOCKET;
while (1) {it
printf("socket connect %d\n", clientSocket);
clientSocket = soap_accept(&tcpSoap);
if (!soap_valid_socket(clientSocket)) {
soap_print_fault(&tcpSoap, stderr);
exit(1);
}class
if (soap_serve(&tcpSoap) != SOAP_OK)
{
soap_print_fault(&tcpSoap, stderr);
printf("soap_print_fault\n");
}cli
printf("IP = %u.%u.%u.%u\n", ((tcpSoap.ip) >> 24) & 0xFF, ((tcpSoap.ip) >> 16) & 0xFF, ((tcpSoap.ip) >> 8) & 0xFF, (tcpSoap.ip) & 0xFF);
soap_destroy(&tcpSoap);
soap_end(&tcpSoap);
}im
//分離運行時的環境 soap_done(&tcpSoap);}