-
-
Save danvideo/47cf9e6fd3ec68faa77507bface41549 to your computer and use it in GitHub Desktop.
Revisions
-
TeWu revised this gist
Sep 23, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ s.close ``` ## .. but can be minified to 7 lines without using instruction terminator ";" .. just 4 fun ;) ### Server: ``` ruby -
TeWu revised this gist
Sep 22, 2011 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,7 @@ s.close ``` ## .. but can be minified to 7 lines without using instruction terminator ";" .. which is just pure art ;) ### Server: ``` ruby -
TeWu revised this gist
Sep 22, 2011 . 1 changed file with 19 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ # TCP client and multithreaded server in 14 lines of Ruby code ### Server: @@ -24,3 +23,21 @@ while line = s.gets end s.close ``` ## .. but can be minified to 7 lines without using instruction terminator ";" ### Server: ``` ruby require "socket" server = TCPServer.open(2626) loop { Thread.fork(server.accept) { |client| client.puts("Hello, I'm Ruby TCP server", "I'm disconnecting, bye :*") or client.close }} ``` ### Client: ``` ruby require "socket" s = TCPSocket.open("localhost", 2626) while line = s.gets do puts "received : #{line.chop}" end s.close ``` -
TeWu revised this gist
Sep 22, 2011 . 1 changed file with 2 additions and 17 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,7 @@ # TCP client and multithreaded server... ## ..in 14 lines of Ruby code ### Server: ``` ruby require "socket" @@ -29,7 +14,7 @@ loop do end ``` ### Client: ``` ruby require "socket" -
TeWu revised this gist
Sep 22, 2011 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,23 @@ # TCP client and multithreaded server... ## ..in 14 lines of Ruby code ``` ruby gem 'active_embed', :git => 'git://github.com/TeWu/ActiveEmbed.git' ``` ``` ruby require "socket" server = TCPServer.open(2626) loop do Thread.fork(server.accept) do |client| client.puts("Hello, I'm Ruby TCP server", "I'm disconnecting, bye :*") client.close end end ``` Server ``` ruby require "socket" server = TCPServer.open(2626) @@ -11,7 +28,9 @@ loop do end end ``` Client ``` ruby require "socket" s = TCPSocket.open("localhost", 2626) -
TeWu revised this gist
Sep 22, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # TCP client and multithreaded server... ## ..in 14 lines of Ruby code Server ``` ruby require "socket" -
TeWu revised this gist
Sep 22, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # TCP client and multithreaded server... ### in 14 lines of Ruby code Server ``` ruby require "socket" -
TeWu created this gist
Sep 22, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ === TCP client and multithreaded server... = in 14 lines of Ruby code Server ``` ruby require "socket" server = TCPServer.open(2626) loop do Thread.fork(server.accept) do |client| client.puts("Hello, I'm Ruby TCP server", "I'm disconnecting, bye :*") client.close end end ``` Client ``` ruby require "socket" s = TCPSocket.open("localhost", 2626) while line = s.gets puts "received : #{line.chop}" end s.close ```