Friday, January 30, 2009

tcpaccept()

This function accepts any incoming connections on a certain listening socket. You must use the tcplisten() script before this one so there is an open listening socket. This script responds to the tcpconnect() script. (The client would use the tcpconnect script and when it got to the server it would be accepted with this script)

Argumento:
This is the socket to listen on. The best way to set this would be to use the tcplisten() script and then set it to a variable and then use that for this argument. Like this:
socket = tcplisten(1337,8,1) //creates the socket
tcpaccept(socket,1) //tells it to accept connections on this socket

Argument1:
Blocking-0/Non Blocking-1 mode.

This function returns the id of the socket. So it is good to set this to a variable for use later. If it doesn't get a connection it will return a negative number. This script should most likely be used
in the step event in a server object so it will constantly be checking if it needs to accept a connection from the client.

Remember in order for this script to work you must already have created a socket using tcplisten().

In actual code the script works like this:

clientSocket=tcpaccept(socket,1) // accept the connections
if clientSocket<=0{ //if it errored
exit //exit this script
}

//if it didn't you can continue scripting here.

No comments:

Post a Comment