Created
December 23, 2015 16:49
-
-
Save vadviktor/dc0e896c16fd98ad737f to your computer and use it in GitHub Desktop.
Ruby unix socket server-client receive-respond
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
require "socket" | |
socket = UNIXSocket.new('/tmp/simple.sock') | |
puts "==== Sending" | |
socket.write("Hello server, can you hear me?\n") | |
puts "==== Getting Response" | |
puts socket.readline | |
socket.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
require "socket" | |
server = UNIXServer.new('/tmp/simple.sock') | |
puts "==== Waiting for connection" | |
socket = server.accept | |
puts "==== Got Request:" | |
puts socket.readline | |
# # Read everything from the socket | |
# while line = socket.readline | |
# puts line.inspect | |
# end | |
puts "==== Sending Response" | |
socket.write("I read you loud and clear, good buddy!") | |
socket.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment