Net connect: Difference between revisions

From ENIGMA
Jump to navigation Jump to search
No edit summary
No edit summary
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{FuncTitle|net_connect|char *addr, char *port, bool serve, bool udp}}
{{FuncTitle|net_connect|addr,port,server,udp}}
== Description ==
== Description ==
//initializes a socket
Initializes a socket as either a client or socket as UDP or TCP-IP using the given network address and port. Supports both IPv4 and IPv6, for clients the identifier indicates the server used for receiving messages. Returns an indentifier for the socket or negative on error.<br>
//serve specifies if this is a server socket (1) or a client socket (0)
''Note: Use 127.0.0.1 to connect the server internally as its own client''
//udp specifies whether to use udp (1) or tcp (0)
//if this is not a server, addr and port specify who to connect to.
//IPv4 and v6 are both supported.
//Returns an identifier for the socket, or negative on error.
//For clients, the identifier indicates the server,
//and may be used to receive messages from them.


== Parameters ==
== Parameters ==
{| class="funcpars"
{| class="funcpars"
! Parameter !! Description
! Parameter !! Data Type !! Description
|-
|-
| addr || string containing network address
| addr || string || network address
|-
|-
| port || string containing network port
| port || string || network port
|-
|-
| serve || boolean
| server || boolean || whether or not the socket is a server (true) or client (false)
|-
|-
| udp || boolean whether or not the connection is udp
| udp || boolean || whether or not the connection is udp (true) or tcp (false)
|}
|}


== Return Values ==
== Return Values ==
'''integer''': Returns the id of the network connection.
'''integer''': Returns the id of the socket or negative on error.


== Example Call ==
== Example Call ==
<syntaxhighlight lang="edl">
<syntaxhighlight lang="edl">
// demonstrates opening a udp network connection
// demonstrates opening a udp network server socket connection
cid = net_connect("111.1.1.1", "100", false, true);
serversocketid = net_connect("0.0.0.0", "25565", false, true);
</syntaxhighlight>
</syntaxhighlight>


__NOTOC__
__NOTOC__
{{Function:ENIGMA}}
{{Function:ENIGMA}}

Latest revision as of 10:30, 29 June 2013

Description

Initializes a socket as either a client or socket as UDP or TCP-IP using the given network address and port. Supports both IPv4 and IPv6, for clients the identifier indicates the server used for receiving messages. Returns an indentifier for the socket or negative on error.
Note: Use 127.0.0.1 to connect the server internally as its own client

Parameters

Parameter Data Type Description
addr string network address
port string network port
server boolean whether or not the socket is a server (true) or client (false)
udp boolean whether or not the connection is udp (true) or tcp (false)

Return Values

integer: Returns the id of the socket or negative on error.

Example Call

// demonstrates opening a udp network server socket connection
serversocketid = net_connect("0.0.0.0", "25565", false, true);