Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created March 30, 2015 07:04
Show Gist options
  • Save komasaru/64286f9c6a4f57e57204 to your computer and use it in GitHub Desktop.
Save komasaru/64286f9c6a4f57e57204 to your computer and use it in GitHub Desktop.
Ruby script to test for socket connection.(Client-side)
#! /usr/local/bin/ruby
# coding: utf-8
#********************************************************
# Ruby script to test for socket connection.(Client-side)
#********************************************************
#
require 'socket'
# サーバ接続 OPEN
sock = TCPSocket.open("localhost", 20000)
while line = $stdin.gets
# ソケットに入力文字列を渡す
sock.puts line
sock.flush
# サーバから返却された文字列を出力
puts sock.gets
end
# ソケット CLOSE
sock.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment