Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Original thread:
Post 4 made on Tuesday June 9, 2015 at 05:44
gopronto
Senior Member
Joined:
Posts:
April 2008
1,453
if you had time you could get pronto to communicate with the Axium processor :)


here is the ccode for the server

The example demonstrates the following:
1. How to set up a TCP server.
2. What happens when a client opens and closes a connection.
3. How to keep client connections open and how to close them.
4. Sending data to the client.
5. Using a postamble for separating commands and replies.
6. Receiving data from the client.
7. Closing a single socket
8. Closing the server (along with all connected sockets).
9. Randomly picking a greeting from a list of possibilities.

The script is started by the Startup macro and then keeps itself running by
returning a non-zero number when run() is called. If the server is shutdown
then the script returns 0 and subsequently terminates.
*/

// The port number that the server allows clients to connect to.
const the_port = 1234

// Allow the server to support up to 10 simultaneous sockets
const max_sockets = 10

static Server:server
static Socket:sockets[max_sockets]

public init (parameter)
{
// Create the server and add a postamble
server = create_ethernet_server (the_port, "", "\r\n",
add_postamble | remove_postamble)
}

static add_socket (Socket:socket)
{
// Add socket to a spare position in sockets
for (new n = 0; n < max_sockets; n++) {
if (sockets[n] == no_socket) {
sockets[n] = socket
break
}
}
}

static remove_socket (Socket:socket)
{
// Clear the entry from sockets
for (new n = 0; n < max_sockets; n++) {
if (sockets[n] == socket) {
sockets[n] = no_socket
break
}
}
}

public data_received_str (Socket:socket, String:str_data)
{
logf("received '%s'\n", str_data)
if (str_data == asString("CLOSE")) {
// Remove the socket that receives the CLOSE command from the sockets
// array so it will be garbage collected. Also send a goodbye message.
send_data_str (socket, asString("Bye!"))
remove_socket (socket)
}
else if (str_data == asString("SHUTDOWN")) {
// Clear the server variable so the server and all its sockets will be
// cleaned up by the garbage collector. Also send a goodbye message for
// everyone back to the socket that sent the SHUTDOWN command.
send_data_str (socket, asString("Bye y'all!"))
server = no_server
}
else {
// Try to convert str_data to a number and then execute the corresponding
// command from the objects table.
new n = strval (str_data)
if (n > 0) {
if (execute_object (StoredObjectIndex:n))
send_data_str (socket, asString("OK"))
}
}
}

public socket_event (Socket:socket, t_socket_event:event)
{
if (event == socket_event_open) {
log("Socket opened\n")
// Store the socket otherwise it will be automatically closed by the
// garbage collector.
add_socket (socket)
// Send a welcome message
send_data_str (socket, strextract(
asString("Hello\tNi hao\tMoin moin!\tCiao"), get_random(3), '\t'))
}
else {
log("Socket closed\n")
remove_socket (socket)
}
}

// run() has to return a non-zero number to keep the script alive
public run()
{
if (server)
return 2000
return 0 // end the script if the server is shutdown
}

Last edited by gopronto on June 9, 2015 06:05.
Pronto still one of the best Wi-Fi Remotes,
www.ikonavs.co.nz and [Link: axiumcontrol.com] Axium Control


Hosting Services by ipHouse