<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ocr.michiyo.me/w/index.php?action=history&amp;feed=atom&amp;title=API%2Finternet</id>
	<title>API/internet - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://ocr.michiyo.me/w/index.php?action=history&amp;feed=atom&amp;title=API%2Finternet"/>
	<link rel="alternate" type="text/html" href="https://ocr.michiyo.me/w/index.php?title=API/internet&amp;action=history"/>
	<updated>2026-08-24T13:45:19Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://ocr.michiyo.me/w/index.php?title=API/internet&amp;diff=1032&amp;oldid=prev</id>
		<title>imported&gt;OCDoc Import: Imported from legacy OpenComputers documentation at ocdoc.cil.li</title>
		<link rel="alternate" type="text/html" href="https://ocr.michiyo.me/w/index.php?title=API/internet&amp;diff=1032&amp;oldid=prev"/>
		<updated>2026-08-24T08:08:27Z</updated>

		<summary type="html">&lt;p&gt;Imported from legacy OpenComputers documentation at ocdoc.cil.li&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Internet API =&lt;br /&gt;
&lt;br /&gt;
This library wraps functionality of Internet cards. Also see the [[Component/internet|Internet Component]] for more low level functionality (such as querying availability of HTTP and TCP functionality).&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;NOTE&amp;#039;&amp;#039;&amp;#039;: It is not possible to create a listening interface on a port. OC can only connect directly to a server to send and receive messages.&lt;br /&gt;
&lt;br /&gt;
* `internet.request(url: string[, data: string or table[, headers: table[, method: string]]]): function`&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Sends an HTTP request to the specified URL, with the specified POST data, if any. If no data is specified, a GET request will be made. The POST data can be in one of two formats: if it&amp;#039;s a string, it will be sent as-is. If it&amp;#039;s a table, it will be converted to a string by assuming that each key is the name of a POST variable, and it&amp;#039;s associated value is the value for that variable. **method** can be explicitly specified to values such as GET, POST, or PUT. Some examples:&lt;br /&gt;
`internet.request(url, {some = &amp;quot;variable&amp;quot;, another = 1})`  &lt;br /&gt;
Will send `some=variable&amp;amp;another=1`.  &lt;br /&gt;
The returned function is an iterator over chunks of the result, use it like so:  &lt;br /&gt;
`for chunk in internet.request(...) do stuff() end`  &lt;br /&gt;
Note that **this method ALSO support HTTPS**. So simply use &lt;br /&gt;
`internet.request(&amp;quot;https://example.com&amp;quot;)` to send a request through HTTPS.&lt;br /&gt;
&lt;br /&gt;
Example specifying PUT:&lt;br /&gt;
`internet.request(&amp;quot;https://example.com&amp;quot;, &amp;quot;put data&amp;quot;, {}, &amp;quot;PUT&amp;quot;)`.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* `internet.socket(address:string[, port:number]):table`&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Opens a TCP socket using an internet component&amp;#039;s `connect` method and wraps it in a table that provides the same methods as a file opened using `filesystem.open`: `read`, `write` and `close` (and `seek`, which will always fail). It is recommended to use `internet.open` instead, which will wrap the opened socket in a [[API/buffer|buffer]], the same way `io.open` wraps files.  &lt;br /&gt;
The read method on the returned socket is &amp;#039;&amp;#039;non-blocking&amp;#039;&amp;#039;. Read will instantly return, but may return an empty string if there is nothing to read. Write &amp;#039;&amp;#039;may&amp;#039;&amp;#039; block until all data has been successfully written. It&amp;#039;ll &amp;#039;&amp;#039;usually&amp;#039;&amp;#039; return immediately, though.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* `internet.open(address:string[, port:number]):table`&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Opens a buffered socket stream to the specified address. The stream can be read from and written from, using `s:read` and `s:write` - in general it can be treated much like files opened using `io.open`. It may often be desirable to set the buffer&amp;#039;s read timeout using `s:setTimeout(seconds)`, to avoid it blocking indefinitely.&lt;br /&gt;
The read method on the returned buffer is &amp;#039;&amp;#039;blocking&amp;#039;&amp;#039;. Read will wait until some data is available to be read and return that.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example usage:&lt;br /&gt;
&lt;br /&gt;
```lua local internet = require(&amp;quot;internet&amp;quot;) local handle = internet.open(&amp;quot;example.com&amp;quot;, 1337) local data = handle:read(10) handle:write(&amp;quot;1234&amp;quot;) handle:close() ``` If you need the HTTP response code, message, and headers, they are retrieved from the internal object, which is stored in the metatable of the returned object. ```lua -- https://github.com/kikito/inspect.lua/blob/master/inspect.lua local inspect = require(&amp;quot;inspect&amp;quot;) local internet = require(&amp;quot;internet&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
local handle = internet.request(&amp;quot;https://www.google.com&amp;quot;) local result = &amp;quot;&amp;quot; for chunk in handle do result = result..chunk end -- Print the body of the HTTP response -- print(result)&lt;br /&gt;
&lt;br /&gt;
-- Grab the metatable for the handle. This contains the -- internal HTTPRequest object. local mt = getmetatable(handle)&lt;br /&gt;
&lt;br /&gt;
-- The response method grabs the information for -- the HTTP response code, the response message, and the -- response headers. local code, message, headers = mt.__index.response() print(&amp;quot;code = &amp;quot;..tostring(code)) print(&amp;quot;message = &amp;quot;..tostring(message)) print(inspect(headers)) ```&lt;br /&gt;
&lt;br /&gt;
This is an example of a basic IRC bot that echos back what you say to it, using the sockets in the internet api. ```lua --this is just a basic split function we&amp;#039;ll use to split the messages function split(data, pat)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  local ret = {}&lt;br /&gt;
  for i in string.gmatch(data,pat) do&lt;br /&gt;
      table.insert(ret,i)&lt;br /&gt;
  end&lt;br /&gt;
  return ret&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
end --config local nickname = &amp;quot;myircbot&amp;quot; local channel = &amp;quot;#mybotchannel&amp;quot;&lt;br /&gt;
&lt;br /&gt;
local net = require(&amp;quot;internet&amp;quot;) local con = net.open(&amp;quot;irc.esper.net&amp;quot;,6667) --define server / port here, this will connect to the server if(con) then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  local line,png,linesplt,msgfrom = &amp;quot;&amp;quot;&lt;br /&gt;
  while(true) do&lt;br /&gt;
      line = con:read() --read a line from the socket&lt;br /&gt;
      print(line)&lt;br /&gt;
      linesplt = split(line,&amp;quot;[^:]+&amp;quot;)&lt;br /&gt;
      if #linesplt &amp;gt;= 2 and string.find(linesplt[2], &amp;quot;No Ident response&amp;quot;) ~= nil then&lt;br /&gt;
          print(&amp;quot;JOIN&amp;quot;)&lt;br /&gt;
          con:write(&amp;quot;USER &amp;quot; .. nickname .. &amp;quot; 0 * :&amp;quot; .. nickname .. &amp;quot;\r\n&amp;quot;) --con:write(msg) is used to send messages, con:read() will read a line&lt;br /&gt;
          con:write(&amp;quot;NICK &amp;quot; .. nickname .. &amp;quot;\r\n&amp;quot;) --for IRC, remember to append the \r\n on the end of all messages&lt;br /&gt;
          con:write(&amp;quot;JOIN :&amp;quot; .. channel .. &amp;quot;\r\n&amp;quot;)&lt;br /&gt;
      elseif linesplt[1] == &amp;quot;PING&amp;quot; or linesplt[1] == &amp;quot;PING &amp;quot; then&lt;br /&gt;
          print(&amp;quot;PING&amp;quot;)&lt;br /&gt;
          png = split(line,&amp;quot;[^:]+&amp;quot;)&lt;br /&gt;
          con:write(&amp;quot;PONG :&amp;quot;..png[#png]..&amp;quot;\r\n&amp;quot;) --respond to pings so we don&amp;#039;t get disconnected&lt;br /&gt;
      elseif string.find(linesplt[1], &amp;quot;PRIVMSG #&amp;quot;) ~= nil then&lt;br /&gt;
          msgfrom = split(linesplt[1],&amp;quot;[^ ]+&amp;quot;)&lt;br /&gt;
          msgfrom = msgfrom[3]&lt;br /&gt;
          con:write(&amp;quot;PRIVMSG &amp;quot;..msgfrom..&amp;quot; :&amp;quot;..linesplt[2]..&amp;quot;\r\n&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
else&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  print(&amp;quot;Connection failed.&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
end ```&lt;br /&gt;
&lt;br /&gt;
For a more advanced example, check out the IRC Client program available in the latest release of OpenComputers: [irc.lua](https://github.com/MightyPirates/OpenComputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/loot/irc/usr/bin/irc.lua)&lt;br /&gt;
&lt;br /&gt;
== Contents ==&lt;br /&gt;
&lt;br /&gt;
{{:API/contents}}&lt;br /&gt;
&lt;/div&gt;</summary>
		<author><name>imported&gt;OCDoc Import</name></author>
	</entry>
</feed>