File tree Expand file tree Collapse file tree 2 files changed +31
-6
lines changed
processing_app/library/net Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -43,12 +43,10 @@ def draw
43
43
input = c . read_string
44
44
# Split input into an array of lines
45
45
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 )
52
50
end
53
51
end
54
52
You can’t perform that action at this time.
0 commit comments