Is there any way to host several txt files on a computer without having to dive deep into socket programming? I have a few requirements, though:

  • People could connect when the app is running
  • No inteference of Windows
  • Instructions on how to create a client side software
  • Python 3.2 Coding

Although the requirements are demanding, any form of help is appreciated. :)

You could use a small web server like bottle. The server side is almost trivial (define a function to serve static files), the client side is straightforward using module urllib. Your app could start/stop the server process and manage the content of the directory where it would store the static files.

You could use a small web server like bottle. The server side is almost trivial (define a function to serve static files), the client side is straightforward using module urllib. Your app could start/stop the server process and manage the content of the directory where it would store the static files.

Could you provide me with an example? I'm not that familiar with urllib or bottle.

Well, here is a working example. First the server program

#!/usr/bin/python3
# -*-coding: utf8-*-
# Title: theserver.py

from bottle import route, run
from bottle import static_file

@route('/static/<filename>')
def server_static(filename):
    return static_file(filename, root='./my_static_files')

if __name__ == "__main__":
    run(host='localhost', port=8080)

Then the client program

#!/usr/bin/python3
# -*-coding: utf8-*-
# Title: theclient.py

from urllib.request import urlopen

if __name__ == "__main__":
    data = urlopen("http://localhost:8080/static/foobar.txt").read()
    print(data)

Also I created a directory my_static_files with a data file foobar.txt.

You could use a small web server like bottle. The server side is almost trivial (define a function to serve static files), the client side is straightforward using module urllib. Your app could start/stop the server process and manage the content of the directory where it would store the static files.

Do I have to stick to port 8000? Or can I change to another port like 23? BTW is there a limit on the files that I store on a bottle server?

You can change to another port, perhaps avoiding well known ports 0 - 1023. For example, port 23 is normally used for a telnet service. I don't think there is a limit on the data files (either the number of files or their size) but if you have a huge file, read it by chunks !

Thanks! You really helped me alot. I'll see if I could finish the config files today and understand the basics of the bottle module.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.