Skip to content

Commit 2632267

Browse files
committed
ruby TCPSocket
1 parent a9bf2e8 commit 2632267

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env jruby -v -W2
2+
# frozen_string_literal: true
3+
require 'propane'
4+
require 'socket'
5+
# Starts a network client that connects to a server on port 80,
6+
# sends an HTTP 1.0 GET request, and prints the results.
7+
8+
class HTTPClient < Propane::App
9+
def settings
10+
size 200, 200
11+
end
12+
13+
def setup
14+
sketch_title 'TCPSocket'
15+
host = 'www.ucla.edu'
16+
port = 80
17+
s = TCPSocket.open host, port
18+
s.send "GET / HTTP/1.1\r\n", 0
19+
s.puts "\r\n"
20+
while line = s.gets
21+
puts line.chop
22+
end
23+
s.close
24+
end
25+
end
26+
27+
HTTPClient.new

processing_app/library/net/shared_canvas_server.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ def draw
4343
input = c.read_string
4444
# Split input into an array of lines
4545
data = input.split("\n")
46-
data.each do |str|
47-
# Split each line to array of string and convert to array of java float
48-
coords = str.split(' ').map(&:to_f).to_java(:float)
49-
# Draw line using received coords
50-
line(*coords)
51-
end
46+
# Split first line to array of string and convert to array of java float
47+
coords = data[0].split(' ').map(&:to_f).to_java(:float)
48+
# Draw line using received coords
49+
line(*coords)
5250
end
5351
end
5452

0 commit comments

Comments
 (0)