#include <winsock2.h>
#include <stdio.h>
#include "cgic.h "
#define SERVPORT 30000
#define MAXDATASIZE 1024
#define SERVIP "127.0.0.1 "
#pragma comment(lib, "ws2_32.lib ")
void getdatafromsocket();
void main (int argc, char *argv[]){
getdatafromsocket();
}
void getdatafromsocket(){
WSADATA wsaData;
SOCKET sConnect;
SOCKADDR_IN serverAddr;
int recvbytes;
int retval;
//初始化Windows Socket2.2
WSAStartup(MAKEWORD(2,2), &wsaData);
// 创建一个新的Socket来连接服务器
sConnect = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
// 填写连接地址信息
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(SERVPORT);
serverAddr.sin_addr.s_addr = inet_addr(SERVIP);
memset(&(serverAddr.sin_zero), 0, sizeof(serverAddr.sin_zero));
// 向服务器发出连接请求
if (connect(sConnect, (SOCKADDR *)&serverAddr, sizeof(SOCKADDR)) == SOCKET_ERROR)
{
printf( "connect failed!\n ");
return ;
}
retval =send(sConnect, "request_data ",12,0);
if (retval == SOCKET_ERROR)
{
printf( "SOCKET_ERROR=%d ",SOCKET_ERROR);
return ;
}
// 接受服务器的回应消息
}
****************
***************
显示:connect failed!
------解决方案--------------------
apche和tomcat的端口一致?
------解决方案--------------------
我没看你的程序,但不明白tomcat下能否运行CGI