Here's a little tutorial in Ruby sockets.
Last active
December 20, 2015 09:19
-
-
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.
This file contains hidden or 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
#send.rb | |
require "socket" | |
message = ARGV | |
host = "test.wahtever.com" | |
port = 2000 | |
TCPSocket.open(host, port) do |s| | |
s.puts(message,0) | |
end |
This file contains hidden or 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
#server.rb | |
require 'socket' | |
server = TCPServer.open(2000) | |
loop { | |
client = server.accept | |
puts client.gets | |
client.close | |
} |
This file contains hidden or 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
#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