Miniwebserver: Unterschied zwischen den Versionen

Aus C3D2
Wechseln zu: Navigation, Suche
(Zu nützlich um zu vergammeln :-))
 
(Python > Ruby)
Zeile 1: Zeile 1:
[[Category:Ruby]]
+
[[Category:Ruby]] [[Category:Python]]
 +
 
 +
=Python=
 +
 
 +
<source lang="python">
 +
#!/usr/bin/env python
 +
import sys
 +
 
 +
from twisted.internet import reactor
 +
from twisted.web import server, static
 +
 
 +
if len(sys.argv) != 3:
 +
    print "Usage: %s <port> <dir>" % (sys.argv[0],)
 +
    sys.exit()
 +
 
 +
root = static.File(sys.argv[2])
 +
site = server.Site(root)
 +
 
 +
reactor.listenTCP(int(sys.argv[1]), site)
 +
reactor.run()
 +
</source>
 +
 
 +
=Ruby=
  
 
<source lang="ruby">
 
<source lang="ruby">

Version vom 14. November 2007, 21:26 Uhr


Python

#!/usr/bin/env python
import sys

from twisted.internet import reactor
from twisted.web import server, static

if len(sys.argv) != 3:
    print "Usage: %s <port> <dir>" % (sys.argv[0],)
    sys.exit()

root = static.File(sys.argv[2])
site = server.Site(root)

reactor.listenTCP(int(sys.argv[1]), site)
reactor.run()

Ruby

#!/usr/local/bin/ruby
require 'webrick'
include WEBrick

if ARGV.size != 2
  puts "Usage: #{$0} <port> <dir>"
  exit
end

s = HTTPServer.new(
  :Port            => ARGV[0].to_i,
  :DocumentRoot    => ARGV[1]
)


trap("INT"){ s.shutdown }
s.start