difference between winsocket and ofxTCPManager

hi every one
I am doing a project that request sending http potocal to Axis ip-cam
in window codeblock
like:

  
[http://192.168.0.90/axis-cgi/com/ptz.cgi?camera=1&zoom=1000](http://192.168.0.90/axis-cgi/com/ptz.cgi?camera=1&zoom=1000)  

seems POCO under codelock cause application crash
it won’t use ofxHttpUtils this time

therefor

I try two way

  1. pure window socket
  
static int postRequest(const char* _host, const char* _file)  
{  
#ifdef WIN32  
    SOCKET sockfd;  
    WSADATA wsaData;  
    #define bufsize 300  
    struct hostent *host;  
    struct sockaddr_in dest_addr;  
    char *Rec_Buf = (char*) malloc(bufsize+1);  
    char request[1000];  
    int rec;  
  
  
    if (WSAStartup(0x202,&wsaData) == SOCKET_ERROR) {  
      WSACleanup();  
      ofLog(OF_LOG_ERROR,"winsocket WSACleanup");  
      return -1;  
    }  
    if ( (host=gethostbyname(_host)) == NULL) {  
       perror("gethostbyname");  
       ofLog(OF_LOG_ERROR," winsocket gethostbyname");  
        return -1;  
    }  
    memset(&dest_addr,0,sizeof(dest_addr));  
    memcpy(&(dest_addr.sin_addr),host->h_addr,host->h_length);  
  
    dest_addr.sin_family= host->h_addrtype;  
    dest_addr.sin_port= htons(80);  
  
  
     if ((sockfd=socket(AF_INET,SOCK_STREAM,0)) < 0) {  
        perror("socket");  
        ofLog(OF_LOG_ERROR,"winsocket socket",);  
        return -1;  
        }  
  
    if (connect(sockfd, (struct sockaddr *)&dest_addr,sizeof(dest_addr)) == -1){  
        perror("connect");  
        ofLog(OF_LOG_ERROR,"winsocket connect");  
        return -1;  
        }  
  
    sprintf(request, "GET /%s HTTP/1.0\n\n",_file );  
    send(sockfd,request,strlen(request),0);  
  
    do{  
       rec=recv(sockfd,Rec_Buf,bufsize,0);  
       if(rec > 0){  
              ofLog(OF_LOG_VERBOSE,"%s",Rec_Buf);  
       }  
    }  
    while(rec > 0);  
    #ifdef WIN32  
    closesocket(sockfd);  
    WSACleanup();  
    #else  
    close(sockfd);  
    #endif  
    #endif  
}  

  1. ofxTcpManager
  
  
    string server = "192.168.0.90";  
    strinf request = "/axis-cgi/com/ptz.cgi?camera=1&zoom=1000";  
    char Rec_Buf[bufsize];  
    ofxTcpManager tcpManager;  
    tcpManager.Create();  
    if(!tcpManager.Connect((char*)server.c_str(),80))  
    {  
        tcpManager.Close();  
        tcpManager.CleanUp();  
        ofLog(OF_LOG_ERROR,"tcpManager.Connect | ");  
  
    }  
    string request = "GET "+action_url+" HTTP/1.0\n\n";  
    if(tcpManager.Write(request.c_str(),strlen(request.c_str())))  
    {  
        ofLog(OF_LOG_VERBOSE,"tcpManager.Write return -1\n");  
    }  
    if(tcpManager.Receive(Rec_Buf, bufsize)<0)  
    {  
        ofLog(OF_LOG_ERROR,"tcpManager.Receive return -1\n");  
    }  
    ofLog(OF_LOG_VERBOSE,"Rec_Buf-\n%s\n",Rec_Buf);  
    delete []Rec_Buf;  
    tcpManager.Close();  
    tcpManager.CleanUp();  

what do you think about this two way to do http request ?
thanks for everyone reply
:wink:

can you post a small example with poco that crashes? I’d be curious what the problem is.

zach: thanks for you reply
forgot to descript which version i am using

actually I used ofxHttpUtils from
http://forum.openframeworks.cc/t/poco-htmlform-image-upload/2929/0

and of version 0062
http://dl.dropbox.com/u/6455413/ofxHttpUtils-cb-0062.zip
and my situation is specify on application and ipcam commuincation.
ipcam and application is a close network connection

while lost connection (e.g wire broken). it crashed

http://forum.openframeworks.cc/t/loading-urls/4138/0

what i am trace from codeblock deugger
i found here

  
  
  
struct ofxHttpResponse{  
	ofxHttpResponse(HTTPResponse& pocoResponse, std::istream &bodyStream, string turl){  
		status=pocoResponse.getStatus();  
		timestamp=pocoResponse.getDate();//got crash here "ofxHttpUtils.h" line 43  
		reasonForStatus=pocoResponse.getReasonForStatus(pocoResponse.getStatus());  
		contentType = pocoResponse.getContentType();  
  
		StreamCopier::copyToString(bodyStream, responseBody);  
        url = turl;  
        pocoResponse.getCookies(cookies);  
	}  
  
	ofxHttpResponse(){}  
  
	int status; 				// return code for the response ie: 200 = OK  
	string reasonForStatus;		// text explaining the status  
	string responseBody;		// the actual response  
	string contentType;			// the mime type of the response  
	Poco::Timestamp timestamp;		// time of the response  
	string url;  
	vector<HTTPCookie> cookies;  
};  
  

and here

  
  
  
// ----------------------------------------------------------------------  
int ofxHttpUtils::doPostForm(ofxHttpForm & form){  
    ofLog(OF_LOG_VERBOSE,"ofxHttpUtils::doPostForm(ofxHttpForm & form)");  
	int ret = -1;  
    try{  
        URI uri( form.action.c_str() );  
        std::string path(uri.getPathAndQuery());  
        if (path.empty()) path = "/";  
  
        HTTPClientSession session(uri.getHost(), uri.getPort());  
        HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);  
        if(auth.getUsername()!="") auth.authenticate(req);  
  
        if(sendCookies){  
        	for(unsigned i=0; i<cookies.size(); i++){  
        		NameValueCollection reqCookies;  
        		reqCookies.add(cookies[i].getName(),cookies[i].getValue());  
        		req.setCookies(reqCookies);  
        	}  
        }  
  
        HTMLForm pocoForm;  
        // create the form data to send  
       if(form.formFiles.size()>0)  
        	pocoForm.setEncoding(HTMLForm::ENCODING_MULTIPART);  
        else  
        	pocoForm.setEncoding(HTMLForm::ENCODING_URL);  
  
        // form values  
        for(unsigned i=0; i<form.formIds.size(); i++){  
            const std::string name = form.formIds[i].c_str();  
            const std::string val = form.formValues[i].c_str();  
            pocoForm.set(name, val);  
        }  
  
        map<string,string>::iterator it;  
        for(it = form.formFiles.begin(); it!=form.formFiles.end(); it++){  
        	string fileName = it->second.substr(it->second.find_last_of('/')+1);  
        	cout << "adding file: " << fileName << " path: " << it->second << endl;  
        	pocoForm.addPart(it->first,new FilePartSource(it->second));  
        }  
  
        pocoForm.prepareSubmit(req);  
        ofLog(OF_LOG_VERBOSE,"pocoForm.write(session.sendRequest(req));");  
  
        pocoForm.write(session.sendRequest(req));  
  
        HTTPResponse res;  
        ofLog(OF_LOG_VERBOSE,"istream& rs = session.receiveResponse(res);");  
        istream& rs = session.receiveResponse(res);//got crash ofxHttpUtils.cpp line 157  
  
		ofxHttpResponse response = ofxHttpResponse(res, rs, path);  
  
		if(sendCookies){  
			cookies.insert(cookies.begin(),response.cookies.begin(),response.cookies.end());  
		}  
  
    	ofNotifyEvent(newResponseEvent, response, this);  
  
    	ret = 0;  
  
    }catch (Exception& exc){  
  
        printf("ofxHttpUtils error--\n");  
  
        //ofNotifyEvent(notifyNewError, "time out", this);  
  
        // for now print error, need to broadcast a response  
        std::cerr << exc.displayText() << std::endl;  
  
    }  
  
    return ret;  
}  
  

got crash here “ofxHttpUtils.h” line 43
and
got crash at “ofxHttpUtils.cpp” line 157

i believe it mostly happens on codeblock POCO lib and close network connection

I hope it may help
many thanks