0

I mean, if i have a winsock in window environmentand i set it to listen on port 80 and ip of server.then i have a file abc.txt or abc.xml .i have to send file from client to http server through http link. how can we send it .I don't know how to send text files.

Please..I need this...so badly.

Thanks in advance!

user1196792
  • 66
  • 2
  • 12
  • When you get a request for the file, just read it and send it through the socket. – Some programmer dude Mar 12 '12 at 11:09
  • Asynchronously, or synchronously? – Chris Gessler Mar 12 '12 at 11:10
  • Uploading files asynchronously with jQuery. http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery – Chris Gessler Mar 12 '12 at 11:10
  • What is it that you actually want to do? a) Create a server program to receive a file, b) Create a client program that sends the file to the server, c) Use an existing program (e.g. web browser) to send the file to the http server, or d) something else? – PauliL Mar 12 '12 at 11:19
  • actually i have to send the on http server , at client side i can read the file using fread() and the corresponding buffer use in send() of winsock for sending to particular http url but i m don't know about server only http link is provided .what server do i.e how it received the file . can by using send function it go to server . how can i create http url for receiving file from client (using vs 2008 window environment) – user1196792 Mar 12 '12 at 11:24
  • @ pauliL thks for get right way.i have to do a) and b) option .for a) option i have to create http url which receive file from client and client send it .there is no role of web browser. main role of http.i m using windows os and vs2008 environment. – user1196792 Mar 12 '12 at 11:28

1 Answers1

0

Setting up a server basically requires the following steps:

  1. Open socket with socket()
  2. Bind socket to an address (usually INADDR_ANY) and a specific port with bind()
  3. Listen to the socket with listen()
  4. Accept a connection with accept(). This returns a new socket number (the client socket)
  5. Now you can receive data from the client socket with recv() and send data with send().

To send a file to the client, just read from the file for example line by line and then send it to the socket with send().

Of course you need to communicate the file name and size before you start sending. (Or use EOF character at the end of file).

For more information, see: msdn: Getting Started with Winsock

PauliL
  • 1,259
  • 9
  • 7
  • actually i have done this by following same step but in this case the server should always executed before the client and server must listen for client every time .i have to send file through http that is we have to created http url of server which receive file and that url is given to client for sending file.but i don't know how to create http server and how to send through http. my task is server provide http url to client and that client send file through http. help me. – user1196792 Mar 13 '12 at 04:17
  • It is difficult to understand your language. However, a server is created as I explain in my answer. The normal way is that the server is running all the time and clients can then connect to it at any time. If you need a http server, you have to implement the http protocol on top of that. It should not be too difficult. The http commands are plain ascii text. – PauliL Mar 18 '12 at 11:15
  • hi paulil i put this work on hold ,so i did see you comment .the task is client have a http url link and when the client want to transfer the file to server it just follow(connect) the http url link for connection to server by this the file is to be transfer . Actually the server provide the http url link but how it do ? how server generate http url ? and when it provided the http link how file is transfer to server? – user1196792 Apr 02 '12 at 12:05