Internet Card: Difference between revisions

From OpenComputers: Rebooted
Jump to navigation Jump to search
imported>OCDoc Import
Imported from legacy OpenComputers documentation at ocdoc.cil.li
 
m SoraFirestorm moved page Item/internet card to Internet Card without leaving a redirect: Page has been unified
 
(2 intermediate revisions by the same user not shown)
Line 16: Line 16:


[[File:internetcard.png|200px]]
[[File:internetcard.png|200px]]
= Component API =
{{APICallback|name=isTcpEnabled|signature=():boolean|description=
Returns whether TCP connections can be made (config setting).
}}
{{APICallback|name=isHttpEnabled|signature=():boolean|description=
Returns whether HTTP requests can be made (config setting).
}}
{{APICallback|name=connect|signature=(address:string[, port:number]):userdata|description=
Opens a new TCP connection. Returns the handle of the connection.
}}
{{APICallback|name=request|signature=(url:string[, postData:string[, headers:table]]):userdata|description=
Sends a new HTTP request. Returns the handle of the connection.
}}
= TCP Socket Object API =
{{APICallback|name=read|signature=([n:number]):string|description=
Tries to read data from the socket stream. Returns the read byte array.
}}
{{APICallback|name=close|signature=()|description=
Closes an open socket stream.
}}
{{APICallback|name=write|signature=(data:string):number|description=
Tries to write data to the socket stream. Returns the number of bytes written.
}}
{{APICallback|name=finishConnect|signature=():boolean|description=
Ensures a socket is connected. Errors if the connection failed.
}}
{{APICallback|name=id|signature=():string|description=
Returns the id for this socket.
After calling <code>finishConnect</code> or <code>read</code>, this socket generates a signal named <code>internet_ready</code> whenever new data is available to be read. It has one parameter which is the socket id.
}}
= HTTP Request Object API =
''FIXME: OC:R introduced a change from a MightyPirates PR that allows for handling HTTP error responses directly instead of automatically throwing an error. Document this.''
{{APICallback|name=read|signature=([n:number]):string|description=
Tries to read data from the response. Returns the read byte array.
}}
{{APICallback|name=response|signature=():number, string, table|description=
Get response code, message and headers.
}}
{{APICallback|name=close|signature=()|description=
Closes an open socket stream.
}}
{{APICallback|name=finishConnect|signature=():boolean|description=
Ensures a response is available. Errors if the connection failed.
}}


== Contents ==
== Contents ==


{{:Item/contents}}
{{:Item/contents}}

Latest revision as of 19:08, 1 September 2026

Internet Card

This card provides access to 'the interwebs'. It allows making HTTP requests and opening TCP sockets, unless disabled in the config. See the Internet API.

Note that the Internet Card is a Tier 2 card and requires an available Tier 2 (or higher) slot to use.

The Internet Card is crafted using the following recipe:

Component API

isTcpEnabled

isTcpEnabled():boolean

Returns whether TCP connections can be made (config setting).

isHttpEnabled

isHttpEnabled():boolean

Returns whether HTTP requests can be made (config setting).

connect

connect(address:string[, port:number]):userdata

Opens a new TCP connection. Returns the handle of the connection.

request

request(url:string[, postData:string[, headers:table]]):userdata

Sends a new HTTP request. Returns the handle of the connection.

TCP Socket Object API

read

read([n:number]):string

Tries to read data from the socket stream. Returns the read byte array.

close

close()

Closes an open socket stream.

write

write(data:string):number

Tries to write data to the socket stream. Returns the number of bytes written.

finishConnect

finishConnect():boolean

Ensures a socket is connected. Errors if the connection failed.

id

id():string

Returns the id for this socket.

After calling finishConnect or read, this socket generates a signal named internet_ready whenever new data is available to be read. It has one parameter which is the socket id.

HTTP Request Object API

FIXME: OC:R introduced a change from a MightyPirates PR that allows for handling HTTP error responses directly instead of automatically throwing an error. Document this.

read

read([n:number]):string

Tries to read data from the response. Returns the read byte array.

response

response():number, string, table

Get response code, message and headers.

close

close()

Closes an open socket stream.

finishConnect

finishConnect():boolean

Ensures a response is available. Errors if the connection failed.

Contents

Items
Components Data Card - Debug Card - Graphics Card - Internet Card - Linked Card - Network Card - Redstone Card - Wireless Network Card
Storage Devices Floppy Disk - EEPROM - Hard Disk Drive - Memory
Upgrades Angel Upgrade - Battery Upgrade - Chunkloader Upgrade - Database Upgrade - Experience Upgrade - Generator Upgrade - Hover Upgrade - Inventory Controller Upgrade - Inventory Upgrade - Leash Upgrade - Navigation Upgrade - Piston Upgrade - Sign I/O Upgrade - Solar Generator Upgrade - Tank Upgrade - Tank Controller Upgrade - Tractor Beam Upgrade - World Sensor Upgrade
Containers Card Container - Upgrade Container - Disk Drive
Others Analyzer - Texture Picker - Component Bus - CPU - APU - Drone Case - Manual - Microcontroller Case - Nanomachines - Remote Terminal - Terminal Server - Server - Tablet Case - Tablet - Crafting Materials - Ink Cartridge - Scrench - Hover Boots - Grog - Loot Disks