Created
March 16, 2012 22:07
-
-
Save cosmo0920/2053129 to your computer and use it in GitHub Desktop.
mikutterでSocket通信を使う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'socket' | |
Plugin.create :socket_tweet do | |
#複数回ツイートを送信するために複数ソケット通信対応サーバーとする | |
@thread = SerialThreadGroup.new | |
@thread.new{ | |
server = TCPServer.open(3900) | |
loop { | |
begin | |
client = server.accept | |
client.puts(Time.now.ctime) | |
#受け取った内容を呟くよ | |
Post.primary_service.update(:message => "#{client.gets}") | |
client.puts "通信が終了しました!" | |
client.puts "正常にツイートが送信されました。" | |
rescue | |
client.puts "IOError." | |
end | |
client.close | |
} | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment