Jump to content

Best practice for UDF that uses TCP connection ?


Myicq
 Share

Recommended Posts

I am finally trying to generalize some communication functions I keep rewriting. But before I start out on too much work, I would like to get some input on what you guys do for UDFs.

The concept is: a socket is connected to a TCP-enabled device (hardware). I am building a function library to set parameters.

I am considering two general principles:

1) I use a global variable for socket, and another to see if we're connected or not.

Func _set_parameter_a($value)
    ;    Using $s as socket..

    ;     Return codes
    ;         2 => not connected
    ;         0 => OK
    If $is_loggedin = 0 Then
        _speak("Not connected!")
        Return 2 ; NOT CONNECTED!!!
    EndIf
    ConsoleWrite("Setting parameter.." & @LF)
    TCPSend($s, "DBS:SET;" & $value & "#")
....
 

 

or..

2) I need to pass a socket to each function call. This will allow use of any  socket name, but will make function calls more complicated..

Func _set_parameter_a($socket, $value)
       ; should do a call to.
       ;   if not _is_socket($socket) then [exit 2]
EndFunc

 

There may be ideas / principles I did not think about. Happy to receive any input or pointers to UDFs that work with sockets in similar way.

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...