Code: Select all
EnableExplicit
If(InitNetwork() = 0)
MessageRequester("Problem", "Network init failed", #PB_MessageRequester_Ok)
End
EndIf
ExamineIPAddresses(#PB_Network_IPv4)
Global igConnectID.i
Global igLocalIP.i = NextIPAddress()
Global sgLocalIP.s = IPString(igLocalIP, #PB_Network_IPv4)
Global sgHost.s = Hostname()
Global sgMsg.s
Global igZwListenPort.i = 8000
Global igZwSendPort.i = 9000
Global igTimeOut.i = 20000
igConnectID = OpenNetworkConnection(sgHost, igZwListenPort, igTimeOut, #PB_Network_TCP|#PB_Network_IPv4, sgLocalIP, igZwSendPort)
If Not(igConnectID = 0)
SendNetworkString(igConnectID, "zw3dremote -r local -f C:\TestFile.Z3)", #PB_Ascii)
CloseNetworkConnection(igConnectID)
Else
MessageRequester("Problem", "Connection to Server failed", #PB_MessageRequester_Ok)
EndIf
sgMsg = "IP: " + sgLocalIP + #CRLF$
sgMsg = sgMsg + "Host: " + sgHost + #CRLF$
MessageRequester("Info", sgMsg, #PB_MessageRequester_Ok)
EndFrom the ZW3D Help:
Can anyone spot an error?About ZW3D Server Mode
ZW3D contains the communications code to act as a server (referred to as ZW3D Server Mode). When ZW3D starts it can create a second communications thread that listens for external commands. The communication is done through TCP/IP sockets and is platform independent.
The ZW3D startup program "zw3d.exe" has the client side built into it. Commands can be sent to ZW3D by using "zw3dremote -r hostname command". This will work across any TCP/IP network. However, zw3d.exe is not required.
The communications client can be written in any language or environment that supports sockets. It is possible to send command line switches, macro commands, and regular ZW3D commands (~xxx, !xxx, $xxx, etc) through this interface. When sending a macro command, data is returned to the client.
Executing ZW3D Server Mode Commands
Running "zw3dremote -r local command" assumes that the command is a ZW3D command that starts with either '~', '!', '$', '&'. If it does not start with any of these symbols then a '~' will automatically be added to the beginning of the command.
To specify additional command line arguments use "zw3dremote -r local -cmd command -xxx ..." This is necessary in order to identify the command correctly among the various command line arguments. To run a macro use "zw3dremote -r local -macro macro_file". To run just a single macro command use "zw3d -r local macro=xxx". To load a file in a running instance of ZW3D use "zw3dremote -r local -f file.Z3".
ZW3D Server Mode Communications
By default ZW3D uses port 8000 to listen and port 9000 to respond. The port numbers can be set by the user. To set the ports use "zw3d -port 3000:4000". This will start ZW3D and ZW3D will listen on port 3000 and respond on port 4000. To send a command to this instance of ZW3D use "zw3dremote -r hostname4000 command". The hostname argument can be the word "local", a computer name as it is recognized on the network, or an IP address such as 192.168.1.1. If the word "local" is used for the hostname, a new instance of ZW3D will be started if it is unable to connect to an already running instance, or if no instances are currently running.
Running ZW3D in Server Mode
By default ZW3D starts in the server mode. To send a command to a copy of ZW3D that is already running on the local machine use "zw3dremote -r local command". If ZW3D is not running, a new instance of ZW3D will be executed. The server mode can be controlled while running ZW3D. Use "~CdServerStart" to start the server mode, "~CdServerStop" to stop the server mode, and "~CdServerReset" to reset and reinitialize the server mode. To get help on the ZW3D command line switches use "zw3dremote -h":
zw3dremote command line options:
/CNSCPRT Use console to print communications information
/F Load and activate file_name
(enclose file_name argument in matching single or double-quote
to handle spaces in filename)
/MACRO Load and run macro_name
(enclose macro_name argument in matching single or double-quote
to handle spaces in filename)
/NOSTDOUT Do not send output to STDOUT
/OUT file Write return data from a remote command to file
/REMOTE Send a command to an already running instance of ZW3D
/R Same as /REMOTE
/WAIT Wait for a command from a running instance of ZW3D
/W Same as /WAIT
Command syntax for /R and /REMOTE options:
zw3dremote /R hostname[:p] /out file command
hostname is the name of the computer that is running ZW3D
p is the optional port number to connect to (default = 8000)
command is the command to be executed by ZW3D
file will contain return data for command after the command is finished
Command syntax for /W and /WAIT options:
zw3dremote /WAIT p
p is the port number to wait for input on
Edit: Add msg re IP and Hostname


