Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.