Sha256: 951faec5b7b94652060d5871ad7ddaa4d58565927ebf377c0460fa707bbec81e

Contents?: true

Size: 987 Bytes

Versions: 5

Compression:

Stored size: 987 Bytes

Contents

# HTTP Client. 
# 
# Starts a network client that connects to a server on port 80,
# sends an HTTP 1.0 GET request, and prints the results. 
# Note that this code is not necessary for simple HTTP GET request:
# Simply calling load_strings("http://www.processing.org") would do
# the same thing as (and more efficiently than) this example.
# This example is for people who might want to do something more 
# complicated later.

load_library 'net'
include_package 'processing.net'

attr_reader :client, :data

def setup
  size(200, 200)
  background(50)
  fill(200)
  @client = Client.new(self, "www.processing.org", 80) # Connect to server on port 80
  client.write("GET / HTTP/1.0\r\n") # Use the HTTP "GET" command to ask for a Web page
  client.write("\r\n")
end

def draw
  if (client.available() > 0)   # If there's incoming data from the client...
    data = client.read_string()  # ...then grab it and print it
    puts data
  end
end

#@todo replace with a pure ruby alternative

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/processing_app/library/net/HTTPClient.rb
ruby-processing-2.6.2 samples/processing_app/library/net/HTTPClient.rb
ruby-processing-2.6.1 samples/processing_app/library/net/HTTPClient.rb
ruby-processing-2.6.0 samples/processing_app/library/net/HTTPClient.rb
ruby-processing-2.5.1 samples/processing_app/library/net/HTTPClient.rb