Class: IrcCat::TcpServer
- Inherits:
-
Object
- Object
- IrcCat::TcpServer
- Defined in:
- lib/irc_cat/tcp_server.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(bot, config) ⇒ TcpServer
constructor
A new instance of TcpServer.
- #ip ⇒ Object
- #port ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(bot, config) ⇒ TcpServer
Returns a new instance of TcpServer.
8 9 10 |
# File 'lib/irc_cat/tcp_server.rb', line 8 def initialize(bot, config) @bot, @config = bot, config end |
Class Method Details
.run(bot, config) ⇒ Object
4 5 6 |
# File 'lib/irc_cat/tcp_server.rb', line 4 def self.run(bot, config) new(bot, config).run end |
Instance Method Details
#ip ⇒ Object
30 31 32 |
# File 'lib/irc_cat/tcp_server.rb', line 30 def ip @config["ip"] || '127.0.0.1' end |
#port ⇒ Object
34 35 36 |
# File 'lib/irc_cat/tcp_server.rb', line 34 def port @config["port"] || '8080' end |
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/irc_cat/tcp_server.rb', line 12 def run Thread.new do socket = TCPserver.new(ip, port) puts "Starting TCP (#{ip}:#{port})" loop do Thread.start(socket.accept) do |s| str = s.recv(@config['size']) sstr = str.split(/\n/) sstr.each do |l| @bot.announce("#{l}") end s.close end end end end |