为什么我的CURL发布我的请求两次,或者为什么我的流包含重复的请求消息? 我在C++中编写了使用卷发来发布请求的代码。我还编写了一段代码,在groovy中接收这个请求。在测试代码时,它似乎会重新发布请求。但我有点不确定,因为它没有反映在我的卷曲痕迹。另一方面,我的套接字流反映了这一点。我猜不出问题出在哪里

为什么我的CURL发布我的请求两次,或者为什么我的流包含重复的请求消息? 我在C++中编写了使用卷发来发布请求的代码。我还编写了一段代码,在groovy中接收这个请求。在测试代码时,它似乎会重新发布请求。但我有点不确定,因为它没有反映在我的卷曲痕迹。另一方面,我的套接字流反映了这一点。我猜不出问题出在哪里,c++,sockets,curl,groovy,C++,Sockets,Curl,Groovy,期望: 服务器端: 如果服务器收到某个请求,它将发送一些响应消息,如果没有,它将只发送一些整数(为了测试,现在它是整数) 客户端: 它偶尔会发送请求并获得响应,如果没有任何请求,它只需侦听以接收消息(例如那些整数) C++Curl调用: if(curl){ curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

期望:

服务器端: 如果服务器收到某个请求,它将发送一些响应消息,如果没有,它将只发送一些整数(为了测试,现在它是整数)

客户端: 它偶尔会发送请求并获得响应,如果没有任何请求,它只需侦听以接收消息(例如那些整数)

C++Curl调用:

 if(curl){

        curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION, 1);

        string Mydata;

        char errbuf[CURL_ERROR_SIZE];
        chunk.memory = (char*)malloc(1);  /* will be grown as needed by the realloc above */
        chunk.size = 0;    /* no data at this point */
        FILE * rfp = fopen("/Users/Uma/request.xml", "r");

        if(rfp != NULL){
            cout<<"File is opened "<<endl;
        }else{
        cout<<"File is close"<<endl;

        }

        curl_easy_setopt(curl, CURLOPT_URL, myUrl);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);

        const char* req= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">  <soapenv:Header/> <soapenv:Body>   <blz:getBank>  <blz:blz>50070010</blz:blz> </blz:getBank>  </soapenv:Body>  </soapenv:Envelope> \n";

        curl_easy_setopt(curl,CURLOPT_HTTPPOST, 1L);

        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req);

        cout<<"requested posted "<<endl;

        curl_easy_setopt(curl, CURLOPT_READFUNCTION, reader);
        curl_easy_setopt(curl, CURLOPT_READDATA, rfp);

        errbuf[0] = 0;

        /* send all data to this function  */

        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);

        curl_easy_setopt(curl,CURLOPT_WRITEDATA,(void *)&chunk);

        curlCode = curl_easy_perform(curl);
        //  always cleanup
        if(curlCode != CURLE_OK  | curlCode != 0) {

            std::cout<<"  traced data "<<traceData<<std::endl;

            size_t len = strlen(errbuf);
            fprintf(stderr, "\nlibcurl: (%d) ", curlCode);
            if(len)
                fprintf(stderr, "%s%s", errbuf,
                        ((errbuf[len - 1] != '\n') ? "\n" : ""));
            else
                fprintf(stderr, "%s\n", curl_easy_strerror(curlCode));
        } else {

            std::cout<<"CURl Code "<<curlCode<<std::endl;

                     /*
             * Now, our chunk.memory points to a memory block that is chunk.size
             * bytes big and contains the remote file.
             */
            std::cout<<"CURL code on error --"<<curlCode<<std::endl;
            printf("%lu bytes retrieved\n", (long)chunk.size);

            //cout<<"My Response ---"<<response<<endl;

            cout<<"My Chunck -- "<<chunk.memory<<endl;
        }                      

        curl_easy_cleanup(curl);
    }
if(curl){
curl_easy_setopt(curl,CURLOPT_调试函数,my_跟踪);
卷曲度(卷曲度,卷曲度(1L));
curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,1);
字符串Mydata;
char errbuf[CURL_ERROR_SIZE];
chunk.memory=(char*)malloc(1);/*将根据上述realloc的需要进行增长*/
chunk.size=0;/*此时没有数据*/
文件*rfp=fopen(“/Users/Uma/request.xml”,“r”);
如果(rfp!=NULL){

coutSorry,但是请求在哪里被重复?我在你的帖子中没有看到这方面的证据。如果有疑问,请与wireshark联系。嗨,谢谢你的回复。我在帖子的最后解释了这一点。一旦我杀死客户端,服务器会再次收到请求的正文。在我杀死客户端后,添加了服务器收到消息的跟踪。
def server = new ServerSocket(2000)
println("Waiting for connection")

String receivedRecord 
while (true) 
{
  println " Input data "      

    server.accept() { socket ->
              socket.withStreams { input, output ->
                    def w = new BufferedWriter(new OutputStreamWriter(output))

            String message = "Connection was successful"
            println message
     def r = new BufferedReader(new InputStreamReader(input))

     println ("Stream ")

    String requestMessage = ""

    def cont = true
    String tempMsg;
     while (cont)
       { 
            tempMsg = r.readLine() 

            if(tempMsg == null)
            {

            cont = false

            }
            else
            {

            requestMessage = requestMessage  +   tempMsg
            }

            println (requestMessage)
            println(cont)

            tempMsg = " "
       }

     int  i = 0;

    while (i <20)
    {
        //String requestMessage = r.readLine()

        //println(" Request Received ")
        //println(requestMessage)

        String echo = "EchoRequestMsg"
        String vehicleSync = "EenheidSynchronisatieRequestMsg"

        if(requestMessage != null )
        {
                        if(requestMessage.toLowerCase().contains(echo.toLowerCase()))
            {
                println (i)
                println ("Echo Request True ")
                sendMessage("Echo", w)
                println(" Echo Message Sent ")

            }
            else if(requestMessage.toLowerCase().contains(vehicleSync.toLowerCase()))
            {     
                println (i)
                println (" Vehicle Sync True ")       
                sendMessage("VehicleSync", w)
                println(" Vehicle Sync Message Sent ")
            }
            else
            {
                println (i)
                println (" push message ")
                i++;
                sendMessage(i, w)
            }

        }


            }
        }
    }
}

def sendMessage(msg, writer) {
    println("Sending: >" + msg + "<")
    writer.writeLine(msg.toString())
    writer.flush();
}
 Input data 
Connection was successful
Stream 
POST / HTTP/1.1
true
POST / HTTP/1.1Host: localhost:2000
true
POST / HTTP/1.1Host: localhost:2000Accept: */*
true
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xml
true
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xmlSOAPAction:urn:getBank
true
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xmlSOAPAction:urn:getBankContent-Length: 251
true
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xmlSOAPAction:urn:getBankContent-Length: 251
true
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xmlSOAPAction:urn:getBankContent-Length: 251<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:blz="http://thomas-bayer.com/blz/">  <soapenv:Header/> <soapenv:Body>   <blz:getBank>  <blz:blz>50070010</blz:blz> </blz:getBank>  </soapenv:Body>  </soapenv:Envelope> 
true
groovy groovyServer.groovy 
Waiting for connection
 Input data 
 Input data 
Connection was successful
Stream 
POST / HTTP/1.1
POST / HTTP/1.1Host: localhost:2000
POST / HTTP/1.1Host: localhost:2000Accept: */*
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xml
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xmlSOAPAction:urn:getBank
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xmlSOAPAction:urn:getBankContent-Length: 256
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xmlSOAPAction:urn:getBankContent-Length: 256
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xmlSOAPAction:urn:getBankContent-Length: 256<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:blz="http://thomas-bayer.com/blz/">  <soapenv:Header/> <soapenv:Body>   <blz:getBank>  <blz:blz>50070010</blz:blz> </blz:getBank>  </soapenv:Body>  </soapenv:Envelope>
POST / HTTP/1.1Host: localhost:2000Accept: */*content-type:text/xmlSOAPAction:urn:getBankContent-Length: 256<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:blz="http://thomas-bayer.com/blz/">  <soapenv:Header/> <soapenv:Body>   <blz:getBank>  <blz:blz>50070010</blz:blz> </blz:getBank>  </soapenv:Body>  </soapenv:Envelope> 
0
 push message 
Sending: >1<
1
 push message 
Sending: >2<
Exception in thread "Thread-1" java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
    at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
    at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
    at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
    at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
    at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
    at java.io.BufferedWriter.flush(BufferedWriter.java:254)