Skip to content

Instantly share code, notes, and snippets.

@gleicon
Created October 4, 2010 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gleicon/610500 to your computer and use it in GitHub Desktop.
Save gleicon/610500 to your computer and use it in GitHub Desktop.
require 'java'
# java.io.IOException
# java.net.InetSocketAddress
# net.fiorix.niosted.Factory
# net.fiorix.niostedi.TCPServer
# net.fiorix.niosted.protocols.LineReceiver
#
require 'niosted.jar'
import "net.fiorix.niosted.protocols.LineReceiver"
import "net.fiorix.niosted.Factory"
import "net.fiorix.niosted.TCPServer"
class FakeProtocol < LineReceiver
def lineReceived(line)
if line.nil?
puts "Got header #{line}"
else
self.transport.write "HTTP/1.1 200 OK\r\n"+
"Etag: \"b32ffe9242ccde98d6e19ed4c9dbc053d4a18155\"\r\n"+
"Content-Length: 14\r\n"+
"Content-Type: text/html; charset=UTF-8\r\n"+
"Server: CycloneServer/0.1\r\n\r\n"+
"Hello, world\r\n"
self.transport.loseConnection()
end
end
def connectionMade()
cl = self.transport.getPeer()
puts "new client connected: #{cl}"
end
def connectionLost(reason)
puts "connection lost: #{reason}"
end
end
class FakeFactory
include Factory
def makeProtocol()
return FakeProtocol.new
end
end
addr = java.net.InetSocketAddress.new("0.0.0.0", 8888)
c = TCPServer.new(addr, FakeFactory.new)
c.run()
@fiorix
Copy link

fiorix commented Oct 5, 2010

já sacou o null ali né malandragem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment