Hi
I want to write a simple client on the iPhone that downloads a file from an http server using only bsd sockets. I searched the web but couldn't find anything helpful. Can you give me a direction?
Thanks
Alex
Hi
I want to write a simple client on the iPhone that downloads a file from an http server using only bsd sockets. I searched the web but couldn't find anything helpful. Can you give me a direction?
Thanks
Alex
This depends on the nature of the server giving you the file. It could be FTP, HTTP, a network file-share, or even something like Gopher or scp. In any case, the basic nature of the problem will be the same:
connect
.read
the data returned by the server and save it to a local fileAn example from http://docs.python.org/library/socket.html
The conversion to C and the handling of the file is left as an exercise to the reader.
# Echo server program
import socket
HOST = '' # Symbolic name meaning all available interfaces
PORT = 50007 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data: break
conn.send(data)
conn.close()
# Echo client program
import socket
HOST = 'daring.cwi.nl' # The remote host
PORT = 50007 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', repr(data)