Skip to content

Commit a893d0e

Browse files
committed
reverse
1 parent 7e8929b commit a893d0e

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'socket'
2+
3+
def settings
4+
size 200, 200
5+
end
6+
7+
def setup
8+
sketch_title 'TCPSocket'
9+
host = 'www.ucla.edu'
10+
port = 80
11+
s = TCPSocket.open host, port
12+
s.send "GET / HTTP/1.1\r\n", 0
13+
s.puts "\r\n"
14+
while line = s.gets
15+
puts line.chop
16+
end
17+
s.close
18+
end

processing_app/library/net/shared_canvas_client.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def settings
1616
end
1717

1818
def setup
19-
sketch_title 'Client'
19+
sketch_title 'Canvas Client'
2020
background(204)
2121
stroke(0)
2222
frame_rate(5) # Slow it down a little
@@ -29,15 +29,17 @@ def draw
2929
# Draw our line
3030
stroke(255)
3131
line(pmouse_x, pmouse_y, mouse_x, mouse_y)
32-
# Send mouse coords to other person
33-
c.write(format("%d %d %d %d\n", pmouse_x, pmouse_y, mouse_x, mouse_y))
32+
# Send mouse coords to other person as spc separated string
33+
c.write(format("%f %f %f %f\n", pmouse_x, pmouse_y, mouse_x, mouse_y))
3434
end
3535
# Receive data from server
3636
return unless c.available > 0
37+
stroke 255, 0, 0
3738
input = c.read_string
38-
# Split values into an array and convert to int
39-
data = input.split(' ').map(&:to_i)
39+
# Split input into an array of lines
40+
data = input.split("\n")
41+
# Split each line to array of string and convert to array of java float
42+
coords = data[0].split(' ').map(&:to_f).to_java(:float)
4043
# Draw line using received coords
41-
stroke(0)
42-
line(*data)
44+
line(*coords)
4345
end

processing_app/library/net/shared_canvas_server.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def settings
1919
end
2020

2121
def setup
22-
sketch_title 'Server'
22+
sketch_title 'Canvas Server'
2323
background(204)
2424
stroke(0)
2525
frame_rate(5) # Slow it down a little
@@ -29,17 +29,19 @@ def setup
2929
def draw
3030
if mouse_pressed?
3131
# Draw our line
32-
stroke(255)
32+
stroke 255
3333
line(pmouse_x, pmouse_y, mouse_x, mouse_y)
3434
# Send mouse coords to other person
35-
s.write(format("%d %d %d %d\n", pmouse_x, pmouse_y, mouse_x, mouse_y))
35+
s.write(format("%f %f %f %f\n", pmouse_x, pmouse_y, mouse_x, mouse_y))
3636
end
3737
# Receive data from client
38-
c = s.available
39-
return if c.nil?
38+
return unless c = s.available
39+
stroke 255, 0, 0
4040
input = c.read_string
41-
# Split values into an array and convert to int
42-
data = input.split(' ').map(&:to_f).to_java(:float)
41+
# Split input into an array of lines
42+
data = input.split("\n")
43+
# Split first line to array of string and convert to array of java float
44+
coords = data[0].split(' ').map(&:to_f).to_java(:float)
4345
# Draw line using received coords
44-
line(*data)
46+
line(*coords)
4547
end

0 commit comments

Comments
 (0)