Unix C++ simple server question: sending data back to browser -


I have written in a simple Unix server C ++ which just waits for an incoming connection, and then when a connection If installed, sends the requested data to display in the customer's browser. I have everything except work to send the data to the customer.

    1. I started the server and set the port number (for this example I have 8181 I will use it).

    2. The client opens the browser and connects to my server and tries to retrieve test.txt to see.

    3. The server accepts incoming connections. Checks to see whether the file exists or not. If the file exists, then it sends the file to the browser.

  • My problem is that I am not sure how the data can be sent back to the browser. I am trying to use Unix system calls to accomplish this, because I believe everyone needs to get back the data.

    Now what I am doing, put the file in a four array buffer and then it is fed into writing (socket id, buffer, strollon (buffer)). When I check it, the server gets the file correctly and reads the data in four array buffers, but typing () command is returning an -1 error value every time.

    I want to receive it where the browser connects and then the text in the browser. Txt is enabled, as well as browser-supported image formats.

    Do read in buffer and then write buffer in a socket "section and just send the file directly to the browser? Here is a part of the code that I am working with now.

      // Create and listen to the binding socket call () ... conn_socket = accept (socketInt, (struct sockaddr *) and caddr, (socklen_t *) And caddrLength); RecvInt = recv (conn_socket, requested file buffer, 1023, 0); if (recvInt> gt; 0) to check that the requestd file exists and co // This file reads that the four array "buffer" int writeInt = write (recvInt, buffer, strlen (buffer)); // it is not working  

    Do anyone have any suggestions? If you want to post more code to me I would be happy to do this, but I believe the problem is in the code given above.

    Thank you for your time.

    when you say :

      int writeInt = Write (RecvInt, buffer, Streln (buffer));  

    The first parameter to write should be the socket to write - you are counting the letters returned by recv ()


    Comments

    Popular posts from this blog

    c# - How to capture HTTP packet with SharpPcap -

    php - Multiple Select with Explode: only returns the word "Array" -

    jquery - SimpleModal Confirm fails to submit form -