Home AMX User Forum NetLinx Studio

IP_SERVER_OPEN problems

I've been looking through the forums with the intent of creating some kind of webpage-based control surface that talks to an NI controller. I've gotten example code and some PHP code for the webpage that seems straightforward enough. I've got my controller responding to itself when I send a periodic string from the IP Client to the IP Server.

But it will only make 1 response to any outside device, then it won't respond again until being rebooted. So here's my code...
DEFINE_DEVICE
dvipserver     = 0:3:0          (* Listener IP Socket *)

DEFINE_CONSTANT
integer nIPPort = 10001

DEFINE_VARIABLE
IP_ADDRESS_STRUCT MyIPAddress

DEFINE_START
GET_IP_ADDRESS(0:0:0,MyIPAddress)
IP_SERVER_OPEN(dvIPServer.Port,nIPPort,IP_TCP)

DATA_EVENT[dvIPServer]
{
    ONERROR:
    {
	SEND_STRING 0,"'error: server=',ITOA(Data.Number)"
   }
    ONLINE:
    {
	SEND_STRING 0,"'online: server'"
    }
    OFFLINE:
    {
	SEND_STRING 0,"'offline: server'"
    }
    STRING:
    {
	SEND_STRING 0,"'string: client=',Data.Text"
	IF (FIND_STRING(Data.Text,'ping',1)) { 
	    SEND_STRING 0:2:0,"'pong',13"
	}
    }
}
Any time I reboot the controller, I can portscan, ping, telnet, or do an fsockopen() in PHP, and get one pair of "online: server" and "offline: server" messages. Then the listener goes dead.

Any help out there for keeping the listener alive?

Thanks,

Comments

  • Nevermind

    NEVERMIND... I got it. It just took clicking the Submit button on the form to get it to work. My mistake? I had been trying to use a port under 10000 earlier. Thought I had already uploaded the change to 10001, but apparently not. It works as advertised on 10001. Sorry for the spaz everyone!
  • AMXJeffAMXJeff Posts: 450
    You have to open the server up again, during the offline event. Once the client disconnects, the server closes as well. See modification to your code example below.
    DEFINE_DEVICE
    dvipserver     = 0:3:0          (* Listener IP Socket *)
    
    DEFINE_CONSTANT
    integer nIPPort = 10001
    
    DEFINE_VARIABLE
    IP_ADDRESS_STRUCT MyIPAddress
    
    DEFINE_START
    GET_IP_ADDRESS(0:0:0,MyIPAddress)
    IP_SERVER_OPEN(dvIPServer.Port,nIPPort,IP_TCP)
    
    DATA_EVENT[dvIPServer]
    {
        ONERROR:
        {
    	SEND_STRING 0,"'error: server=',ITOA(Data.Number)"
       }
        ONLINE:
        {
    	SEND_STRING 0,"'online: server'"
        }
        OFFLINE:
        {
    	SEND_STRING 0,"'offline: server'"
    
                    IP_SERVER_OPEN(dvIPServer.Port,nIPPort,IP_TCP)
        }
        STRING:
        {
    	SEND_STRING 0,"'string: client=',Data.Text"
    	IF (FIND_STRING(Data.Text,'ping',1)) { 
    	    SEND_STRING 0:2:0,"'pong',13"
    	}
        }
    }
    

    I've been looking through the forums with the intent of creating some kind of webpage-based control surface that talks to an NI controller. I've gotten example code and some PHP code for the webpage that seems straightforward enough. I've got my controller responding to itself when I send a periodic string from the IP Client to the IP Server.

    But it will only make 1 response to any outside device, then it won't respond again until being rebooted. So here's my code...

    Any time I reboot the controller, I can portscan, ping, telnet, or do an fsockopen() in PHP, and get one pair of "online: server" and "offline: server" messages. Then the listener goes dead.

    Any help out there for keeping the listener alive?

    Thanks,
  • AMXJeff wrote:
    You have to open the server up again, during the offline event.

    Ah, thanks Jeff. You are right. Below 10000, I think the OPEN tried and failed right away, giving me those two "open" and "close" messages. Over 10000, the port opens and stays open, taking data, until the client disconnects. Then it's got to be re-opened again.
  • yuriyuri Posts: 861
    Ah, thanks Jeff. You are right. Below 10000, I think the OPEN tried and failed right away, giving me those two "open" and "close" messages. Over 10000, the port opens and stays open, taking data, until the client disconnects. Then it's got to be re-opened again.

    so any port under 10000 closed itself after a while?

    i'm having difficulties keeping port 2001 -> 2004 open (Extron IPLTS4 connection)
  • viningvining Posts: 4,368
    I thought all HTTP sessions automatically close upon transfer of data or time out. You are connectiing to a web server with PHP in the HTML, right?

    What's this about above port 10001? Is there some reference you could share?
  • DHawthorneDHawthorne Posts: 4,584
    vining wrote:
    I thought all HTTP sessions automatically close upon transfer of data or time out. You are connectiing to a web server with PHP in the HTML, right?

    What's this about above port 10001? Is there some reference you could share?

    That is the HTML standard: send your request, get a response, disconnect.
  • vining wrote:
    I thought all HTTP sessions automatically close upon transfer of data or time out. You are connectiing to a web server with PHP in the HTML, right? What's this about above port 10001? Is there some reference you could share?

    1. My testing shows that it takes a couple minutes for an IP_SERVER_OPEN connection to time out (which isn't good in my case). I've added an IP_SERVER_CLOSE after it gets data, processes, and sends back a result. Then in the OFFLINE statement, I open the server connection again. That seems to work OK, although I worry that If there's any bugs in the OPEN and CLOSE functions, this will eventually cause problems.

    2. I read in another post on this forum, someone mentioned they used "any port above 10000" for their connection. I've frequently used port 9999 for special IP apps, so I tried that first. I have no idea why 9999 didn't work for me. When I changed to port 10001, it did. Maybe someone else knows more.
Sign In or Register to comment.