Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created March 30, 2015 07:00
Show Gist options
  • Save komasaru/50b9ffedea541b1300f8 to your computer and use it in GitHub Desktop.
Save komasaru/50b9ffedea541b1300f8 to your computer and use it in GitHub Desktop.
Ruby script to test for socket connection.(Server-side)
#! /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