Contents 

Overview
Fundamentals
Variable declaration
Variable assignment
Adding variables
Setting variables
Include function
Evaluate function
Constants
Arrays
If...then...else Statement
For Statement
Foreach Statement
While Statement
Function definition
Operators
Comments
Performance Profiler
Functions
String processing
Overview
Length
Left
Right
Mid
Trim
TrimLeft
TrimRight
ToUpper
ToLower
Find
FindOneOf
ReverseFind
WildcardCompare
Tokenize
RegularExpressionMatch
RegularExpressionParse
Operator [ ]
Delete
Remove
Replace
MakeReverse
SpanIncluding
SpanExcluding
ToUTF8
FromUTF8
File IO routines
Overview
ReadData
ReadDataToString
WriteData
ReadString
WriteString
AppendString
GetLastFileError
EOF
CloseFile
CreateDir
RemoveDir
ChangeDir
GetCurrentDir
IsFileExist
FileSize
CopyFile
MoveFile
RemoveFile
Seek
SeekToBegin
SeekToEnd
SetFileEncoding
SetUseUnicodeBOM
ListFiles
CountFilesInFolder
MapNetworkDrive
DisconnectNetworkDrive
EnumerateDrives
GetDriveInfo
Time routines
Overview
Sleep
MilliSleep
GetTime
GetTimeString
FormatTime
ConvertToUnixTime
GetTickCount
SNMP management
Overview
SnmpGet
SnmpGetNext
SnmpGetBulk
SnmpSet
GetPduErrorStatus
GetPduErrorString
GetPduErrorIndex
GetVarCount
GetVarAt
CreatePdu
AppendVar
GetVarOID
GetVarResolvedName
GetVarValue
GetVarResolvedValue
GetVarResolvedDescription
GetVarSyntax
CreateVar
GetPduIp
GetPduEnterprise
GetPduTrapCode
GetPduTrapName
GetPduResolvedTrapName
GetPduResolvedTrapDescription
GetPduCommunity
GetPduVersion
SendTrap
ForwardTrap
PrepareTrapPdu
SetMaxPduSize
SNMP MIB functions
Overview
LoadMIB
ResolveOID
GetOidByName
ResolveTrap
UnloadMIB
QuickMibLookup
Cryptography
Overview
Encrypt
Decrypt
CalculateMD5Hash
CalculateSHA1Hash
HMAC
BuildKeyFromPassword
Base64Encode
Base64Decode
CRC16
CRC32
HexStringToByteArray
ByteArrayToHexString
Skype integration functions
Overview
SkypeGetContacts
SkypeSendChatMessage
SkypeSendSMS
SkypeCallAndSpeakText
XML processing
Overview
ReadXml
WriteXml
GetXmlTag
CreateXml
InsertAttr
IsXmlValid
SelectXmlNodes
XslTransform
GetAttrString
GetAttrInt
GetAttrDouble
GetXmlBody
GetXmlAttributes
SetXmlBody
AddChild
GetChildrenCount
GetChildAt
JSON processing
Overview
ParseJSON
ToJSON
FTP functions
Overview
FtpOpen
FtpClose
FtpGetCurrentDir
FtpSetCurrentDir
FtpCreateDir
FtpRemoveDir
FtpGet
FtpPut
FtpRemoveFile
FtpRenameFile
FtpListFiles
FtpCountFilesInFolder
TFTP functions
Overview
TFTPGet
TFTPPut
Networking functions
Overview
HttpPing
HttpGet
HttpPost
OpenTCPConnection
OpenUDPSocket
SendTCPData
SendUDPData
IsDataAvailable
ReadTCPData
ReadUDPData
CloseSocket
TCPListen
TCPAcceptConnection
GetHostByAddress
GetAddressByName
DnsQuery
SendMail
SendMailEx
SendHtmlMail
TestSMTPConnection
GetHostName
GetHostDnsSuffix
GetSocketName
SetSocketOption
TestPOP3Connection
POP3GetStats
POP3 Mail Client Example
Ping
TraceRoute
GetMacAddress
EnumerateSharedResources
Working with serial ports and USB HID devices
Overview
OpenSerialPort
CloseSerialPort
IsSerialDataAvailable
ReadSerialData
WriteSerialData
WriteSerialControlChar
SetSerialFlowControl
ClearSerialDTR
ClearSerialRTS
SetSerialDTR
SetSerialRTS
SetSerialXOFF
SetSerialXON
SetSerialBreak
ClearSerialBreak
GetSerialModemStatus
USBOpen
USBClose
USBWriteFeatureReport
USBReadFeatureReport
USBWriteData
USBReadData
USBEnumerateDevices
USBGetFeatureReportLength
Working with Ginkgo USB-I2C adapter
Overview
USBAdapterOpen
USBAdapterClose
USBAdapterBoardInfo
USBAdapterSetPins
USBAdapterResetPins
USBAdapterSetInput
USBAdapterSetOutput
USBAdapterSetOpenDrain
USBAdapterReadGPIO
USBAdapterGetErrorString
USBAdapterSetReadBufferSize
USBAdapterInitI2C
USBAdapterInitTimeConfig
USBAdapterInitADC
USBAdapterInitPWM
USBAdapterInitCNT
USBAdapterInitUART
USBAdapterReadI2C
USBAdapterReadSlaveI2C
USBAdapterReadADC
USBAdapterReadUART
USBAdapterWriteI2C
USBAdapterWriteSlaveI2C
USBAdapterWriteUART
USBAdapterSetPWMPulse
USBAdapterSetPWMPeriod
USBAdapterStartPWM
USBAdapterStopPWM
USBAdapterSetCounter
USBAdapterStartCounter
USBAdapterGetCounter
USBAdapterStopCounter
Working with GSM modems
Overview
SendSMS
RetrieveAllSMSMessages
RetrieveUnreadSMSMessages
DeleteSMSMessage
DeleteAllSMSMessages
Working with zip archives
Overview
ZipFiles
UnzipFiles
AddFileToZip
AddFolderToZip
RemoveFileFromZip
ListFilesInZip
UnzipFile
Mathematical routines
Overview
abs
acos
asin
atan
CalculateScaleFactor
cos
cosh
exp
IsNAN
log
log10
max
mod
pow
ScaleArray
sin
sinh
sqrt
tan
tanh
Charts
Overview
CreateGauge
CreatePieChart
CreateBarChart
CreateLineChart
CreateXYLineChart
Database Interface
Overview
DBOpen
DBClose
DBExecuteSQL
DBSelect
DBInsertSelect
DBGetSQLStatus
DBGetSQLErrorString
CompactAccessDB
GetDataSources
CreateDataSource
RemoveDataSource
DBSetLoginTimeout
DBSetQueryTimeout
Using in-memory cache
Overview
AddCacheEntry
RemoveCacheEntry
RemoveAllCacheEntries
GetCacheEntriesCount
CacheLookup
FindEntryInCache
CacheLoad
CacheSave
CacheToString
Round Robin Databases
Overview
RrdCreate
RrdUpdate
RrdRemove
RrdFetch
RrdGetCurrentValue
Event Log functions
Overview
EventLogGetNumberOfRecords
EventLogGetOldestRecord
EventLogReadRecord
EventLogWaitForEvent
EventLogWriteRecord
Service Control Manager
Overview
SCMEnumerateServices
SCMGetServiceInfo
SCMStartService
SCMStopService
Parameter Files
Overview
GetParameterCount
GetParameterName
GetParameterType
GetParameterValue
GetParameterDisplayName
GetParameterDescription
GetParameterEnumValues
GetParameterEnumValue
GetEnumValueNameFromInt
Process management functions
Overview
ExecuteCommand
RunCommand
FindProcess
GetProcesses
RedirectOpen
RedirectClose
RedirectGetStdOut
RedirectGetStdError
RedirectSendInput
GetProcessorUsage
GetMemoryUsage
WMI functions
Overview
WMIOpen
WMIClose
WMIQuery
WMIGetErrorStatus
Short Message Peer-to-Peer (SMPP)
Overview
SmppOpen
SmppClose
SmppSubmitMessage
SmppEnquireLink
SmppGetLastError
Query functions
Overview
LDAPQuery
REGQuery
CSVQuery
TSVQuery
EventLogQuery
TextLineQuery
TextWordQuery
FSQuery
GetQueryStatus
GetQueryErrorString
Microsoft Outlook integration
Overview
OpenOutlookSession
CloseOutlookSession
OutlookSendMail
OutlookSendMeetingRequest
OutlookCreateTask
Ports IO
Overview
ReadPort
WritePort
IBM WebSphere Message Queue (MQ) functions
Overview
WMQConnect
WMQDisconnect
WMQOpenQueue
WMQCloseQueue
WMQPutMessage
WMQGetMessages
WMQGetManagerStatus
WMQGetQueueStatus
WMQSetOptions
Other routines
Overview
Println
MessageBox
ToString
ToInteger
ToDouble
ToChar
ToByte
ToXml
LogMessage
GetLastSystemError
GetSystemErrorString
GetEnvironmentStrings
GetEnv
SetEnv
IsVariableExist
IsArrayElementExist
GetArraySize
GetArrayIndex
PreallocateArrayHashTable
Sort
IsBitSet
SetBit
ClearBit
ToggleBit
Beep
GetNetDecisionSystemDir
PlaySound
TextToSpeech
Rand
SeedRand
GenerateUID
RGB
Logon
Reboot

NetDecision Script Language Reference

Prev Page Next Page

TCPAcceptConnection

int TCPAcceptConnection(int serverSocket)

Return Value

Returns the socket number assigned to TCP server session by the system. If operation fails returns FAIL.

Parameters

serverSocket - integer variable containingthe TCP server socket identifier/descriptor previously opened by TCPListen() function call.

Remarks

Use this method to accept a connection from the client on a TCP server socket.

Package

Plug in module: nd_tcpplg.npl

Example

###########################################################
# NetAct ASCII Alarm emulator (Emulates wiimanmx service)
###########################################################
# Copyright © NetMechanica - All rights reserved
###########################################################
        
# create TCP server socket and start listener
int nServerPort = 3000        
int nServerSocket = TCPListen(nServerPort)  
 
array clientSockets
int nLastClient = 0
 
if (nServerSocket == FAIL)
  Println("Failed to create TCP server socket")
  stop                               
else
  Println("Listening on TCP port ", nServerPort)
endif
                                    
# accept TCP clients
func AcceptPendingConnections()
  while(TRUE)
     int nClientSocket = TCPAcceptConnection(nServerSocket)       
     if (nClientSocket == FAIL)
       return FAIL  
     else
       Println("Accepting TCP client connection...")
       clientSockets[nLastClient] = nClientSocket # put socket to array of clients   
       nLastClient++
     endif
  endwhile
endfunc
 
func CloseClientConnection(int nClientSock)
  int connections = GetArraySize(clientSockets)
  for(int i=0; i<connections; i++)
     if (clientSockets[i] == nClientSock)
       clientSockets[i] = FAIL
       CloseSocket(nClientSock)
       Println("Closing client socket: ", nClientSock)
       return OK
     endif
  endfor
endfunc
 
func SendAlarmsToClients()   
     
  foreach(int nClientSock in clientSockets)
    
      if (nClientSock != FAIL)
    
       Println("Sending alarms to client: ", nClientSock)
     
       if (SendTCPData(nClientSock, "#S#5721547      W    MOCMSS1        MOC Level 2                    MSS         " + LF) != OK)
          Println("Failed to send data to ", nClientSock)
          CloseClientConnection(nClientSock)
          return FAIL
       endif 
     
       SendTCPData(nClientSock, "PLMN-PLMN/MSC-376163                                      " + LF)
       SendTCPData(nClientSock, "ERROR IN COMPONENT HANDLING                           " + LF)
       SendTCPData(nClientSock, "Started    2013-10-29 10:27:26      -                 " + LF)
       SendTCPData(nClientSock, "IntId      2152031                  NotifId       65535                        " + LF)
       SendTCPData(nClientSock, "Suppl info 78 38 06 00 0F 97 66 89 10 81 64 65 90 6F FF                        " + LF)
       SendTCPData(nClientSock, "User info                                                                      " + LF)
       SendTCPData(nClientSock, "Object     MOCMSS1                  EQUIPMENT                                  " + LF)
       SendTCPData(nClientSock, "#E#")
       
       SendTCPData(nClientSock, "#S#5721598      W    FBSC_44        10 International Business Park globalScope " + LF)
       SendTCPData(nClientSock, "PLMN-PLMN/BSC-234348/TCSM-317                             " + LF)
       SendTCPData(nClientSock, "UNIT FOUND FAULTY BY ALARM SYSTEM                     " + LF)
       SendTCPData(nClientSock, "Started    2013-10-29 10:24:33      -                 " + LF)
       SendTCPData(nClientSock, "IntId      1832554                  NotifId       148298                       " + LF)
       SendTCPData(nClientSock, "Suppl info FFFF FFFF 00001010 00000000 00000000 00000000 00000000 00000000     " + LF)
       SendTCPData(nClientSock, "User info                                                                      " + LF)
       SendTCPData(nClientSock, "Object     MOC BSC 44               EQUIPMENT                                  " + LF)
       SendTCPData(nClientSock, "#E#")
   
       SendTCPData(nClientSock, "#S#5721598      W    FBSC_44        10 International Business Park globalScope " + LF)
       SendTCPData(nClientSock, "PLMN-PLMN/BSC-234348/TCSM-353                             " + LF)
       SendTCPData(nClientSock, "UNIT FOUND FAULTY BY ALARM SYSTEM                     " + LF)
       SendTCPData(nClientSock, "Started    2013-10-29 10:24:38      -                 " + LF)
       SendTCPData(nClientSock, "IntId      1832560                  NotifId       148299                       " + LF)
       SendTCPData(nClientSock, "Suppl info FFFF FFFF 00001010 00000000 00000000 00000000 00000000 00000000     " + LF)
       SendTCPData(nClientSock, "User info                                                                      " + LF)
       SendTCPData(nClientSock, "Object     MOC BSC 44               EQUIPMENT                                  " + LF)
       SendTCPData(nClientSock, "#E#")
   
       SendTCPData(nClientSock, "#S#5721574      W    HLR6           MOC                            MOC_NSS     " + LF)
       SendTCPData(nClientSock, "PLMN-PLMN/HLR-947282                                      " + LF)
       SendTCPData(nClientSock, "DATA ERROR FOUND BY PROTOCOL                          " + LF)
       SendTCPData(nClientSock, "Started    2013-10-29 10:27:34      -                 " + LF)
       SendTCPData(nClientSock, "IntId      1608033                  NotifId       65535                        " + LF)
       SendTCPData(nClientSock, "Suppl info 24 2D 08 00 0A 91 65 96 84 59 07 FF FF FF FF                        " + LF)
       SendTCPData(nClientSock, "User info                                                                      " + LF)
       SendTCPData(nClientSock, "Object     HLR6                     EQUIPMENT                                  " + LF)
       SendTCPData(nClientSock, "#E#")
     
     endif
 
  endforeach
 
endfunc          
 
# Main TCP listener loop
 
int nCount = 0
 
while(TRUE)
 
  AcceptPendingConnections()
 
  MilliSleep(100)
 
  if(nCount == 50)
     SendAlarmsToClients()
     nCount = 0
  else
     nCount++
  endif
endwhile


  

   
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)