Thursday, January 29, 2009

tcplisten()

This function creates a listening socket to monitor a port for incoming connections. You use this to open up a 'door' for the messages to come to. This function has 3 arguments.

Argument 0:
(A number)The port to listen on. As stated before a port number can be anything from 1024 to 49151

Argument 1:
(A number) This is the max number of people allowed to be connected but not accepted.

Argument 2:
(true or false)Blocking or Non Blocking mode. (0=Blocking, 1=Non-Blocking) This affects the tcpaccept() script. Remember that false=0 and true=1

This function returns the id of the socket or a negative number if it had an error. So you may want to attach a variable to it to check its status easier. This script in action would be used to start a listening socket to accept connections from players. In actual scripting it would be used like this:

listen=tcplisten(1337,8,true) //opens a listening socket and gives it the id 'listen'
if listen<=0{ //if it errors(returns a negative number)
show_message("Could not create listening socket") //tell them
exit //exit the script
}

//the script can continue on here because if it errored it would have been stopped by the above code(exit)

No comments:

Post a Comment