Skip to content

Instantly share code, notes, and snippets.

@ryancastro
Last active December 20, 2015 09:19
Show Gist options
  • Save ryancastro/6107158 to your computer and use it in GitHub Desktop.
Save ryancastro/6107158 to your computer and use it in GitHub Desktop.
Using Ruby sockets, because the examples in the documentation don't work at all. Simple client/server messaging example.
#send.rb
require "socket"
message = ARGV
host = "test.wahtever.com"
port = 2000
TCPSocket.open(host, port) do |s|
s.puts(message,0)
end
#server.rb
require 'socket'
server = TCPServer.open(2000)
loop {
client = server.accept
puts client.gets
client.close
}

Here's a little tutorial in Ruby sockets.

#udp.rb
#DOS potential?
#just make message 10,000 characters long.
#scary.
#500.times do
UDPSocket.open() do |s|
s.connect(host, port)
s.send("message",0)
end
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment