Created
March 30, 2015 07:00
-
-
Save komasaru/50b9ffedea541b1300f8 to your computer and use it in GitHub Desktop.
Ruby script to test for socket connection.(Server-side)
This file contains 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
#! /usr/local/bin/ruby | |
# coding: utf-8 | |
#******************************************************** | |
# Ruby script to test for socket connection.(Server-side) | |
#******************************************************** | |
# | |
require 'socket' | |
# サーバ接続 OPEN | |
serv = TCPServer.new(20000) | |
loop do | |
# ソケット OPEN (クライアントからの接続待ち) | |
sock = serv.accept | |
while str = sock.gets.chomp | |
# クライアントから受信した文字列を出力 | |
puts "RECV : #{str}" | |
# クライアントへ文字列返却 | |
sock.puts "SERVER received '#{str}' from CLIENT." | |
end | |
# ソケット CLOSE | |
sock.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment