PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Optimizing the connections for an IP address
  • Time-out
  • Connecting to an infrared port
  • Name resolution
  • Required permissions
  • Required application feature
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Connects a client computer to a given socket.
Notes:
  • UDP sockets: The UDP protocol being a "connectionless" protocol, SocketConnect cannot be used with the UDP protocol. To send or receive data with the UDP protocol, you must create a UDP socket (SocketCreateUDP) then send/receive data with the "special UDP" syntaxes of SocketWrite and SocketRead.
  • SSL sockets: To send or receive data with the SSL protocol, you must create an SSL socket (SocketCreateSSL) and connect to this socket with SocketConnectSSL.
  • Communication with robots or with non-WINDEV applications: To simplify the exchanges of data by socket, a transmission mode is initialized by default. For a communication with an external module (non-WINDEV application, robot, ...), this transmission mode can prevent the communications from operating properly. SocketChangeTransmissionMode is used to change this transmission mode (the SocketNoEndTag constant allows you not to modify the frames read and written).
  • Versions 22 and later
    WEBDEV - Browser code Websockets: The WebSockets are used to communicate from a Web application (Intranet or Internet site run in a browser) to a Web server by using sockets. SocketConnect is used to connect to the WebSockets server. See Managing WebSockets for more details.
    New in version 22
    WEBDEV - Browser code Websockets: The WebSockets are used to communicate from a Web application (Intranet or Internet site run in a browser) to a Web server by using sockets. SocketConnect is used to connect to the WebSockets server. See Managing WebSockets for more details.
    WEBDEV - Browser code Websockets: The WebSockets are used to communicate from a Web application (Intranet or Internet site run in a browser) to a Web server by using sockets. SocketConnect is used to connect to the WebSockets server. See Managing WebSockets for more details.
Reminder: A socket is a communication resource used by the applications to communicate between computers regardless of the network type.
Versions 15 and later
Android This function is now available for the Android applications.
New in version 15
Android This function is now available for the Android applications.
Android This function is now available for the Android applications.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
Universal Windows 10 App This function is now available for the Windows Phone applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
Universal Windows 10 App This function is now available for the Windows Phone applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Universal Windows 10 App This function is now available for the Windows Phone applications.
Versions 18 and later
Android Widget This function is now available in Android Widget mode.
New in version 18
Android Widget This function is now available in Android Widget mode.
Android Widget This function is now available in Android Widget mode.
Versions 22 and later
WEBDEV - Browser code This function is now available in browser code.
New in version 22
WEBDEV - Browser code This function is now available in browser code.
WEBDEV - Browser code This function is now available in browser code.
Versions 23 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 23
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Example
WINDEVWEBDEV - Server codeAndroidAndroid Widget iPhone/iPadWindows MobileUniversal Windows 10 AppJavaPHP
IF SocketConnect("Server", 8000) = False THEN
Error("Connection error" + ErrorInfo(errMessage))
END
Versions 22 and later
WEBDEV - Browser code
SocketConnect("client", "ws://<ServerIPAddress>:5001", ReturnProc)
PROCEDURE ReturnProc(nEvent, sMessage)
gsRes is string = ""

SWITCH nEvent
CASE SocketOpening:
SocketWrite("client", "Send message from the browser.")
RETURN
CASE SocketMessage: gsRes += [CR] + "Receiving message: " + sMessage
CASE SocketClosing: gsRes += [CR] + "Closing the socket"
CASE SocketError:
gsRes += [CR] + "Error of socket: " + sMessage
RETURN
OTHER CASE
END
Info(gsRes)
New in version 22
WEBDEV - Browser code
SocketConnect("client", "ws://<ServerIPAddress>:5001", ReturnProc)
PROCEDURE ReturnProc(nEvent, sMessage)
gsRes is string = ""

SWITCH nEvent
CASE SocketOpening:
SocketWrite("client", "Send message from the browser.")
RETURN
CASE SocketMessage: gsRes += [CR] + "Receiving message: " + sMessage
CASE SocketClosing: gsRes += [CR] + "Closing the socket"
CASE SocketError:
gsRes += [CR] + "Error of socket: " + sMessage
RETURN
OTHER CASE
END
Info(gsRes)
WEBDEV - Browser code
SocketConnect("client", "ws://<ServerIPAddress>:5001", ReturnProc)
PROCEDURE ReturnProc(nEvent, sMessage)
gsRes is string = ""

SWITCH nEvent
CASE SocketOpening:
SocketWrite("client", "Send message from the browser.")
RETURN
CASE SocketMessage: gsRes += [CR] + "Receiving message: " + sMessage
CASE SocketClosing: gsRes += [CR] + "Closing the socket"
CASE SocketError:
gsRes += [CR] + "Error of socket: " + sMessage
RETURN
OTHER CASE
END
Info(gsRes)
Syntax
WINDEVWEBDEV - Server codeAndroidAndroid Widget iPhone/iPadWindows MobileUniversal Windows 10 AppJavaPHP

Connecting to a socket Hide the details

<Result> = SocketConnect(<Socket Name> , <Port Number> [, <Address> [, <Maximum Time-out>]])
<Result>: Boolean
  • True if the function was successful,
  • False otherwise. To find out the error details, use ErrorInfo.
<Socket Name>: Character string (with quotes)
Name that will be given to the connection opened on the server socket. This name will be used by all socket functions.
WINDEV Caution: The socket name is case sensitive.
<Port Number>: Integer
Port number of socket. If you are using a socket associated with a preset protocol, use the port number associated with the protocol.
If the socket was created by a WINDEV application, this number must be included between 5 000 and 65 000. In this case, the number must be identical to the port number specified in SocketCreate.
<Address>: Optional character string (with quotes)
Address of server. If this parameter is not specified, the server is sought on the current computer. This address can be given in the following format:
  • IP address in XXX.XXX.XXX.XXX format (125.5.110.100 for example).
  • URL containing the server name (www.windev.com for example). This syntax is recommended.
WINDEVWEBDEV - Server code The address can also correspond to the IP address returned by NetIPAddress.
<Maximum Time-out>: Optional integer or optional Duration
Maximum time-out (in milliseconds) for establishing the connection. This time-out will be used if the server refuses the connection (SocketDeny). In this case, the connection will not be locking. This parameter can correspond to:
  • an integer corresponding to the number of milliseconds,
  • a Duration variable,
  • Versions 23 and later
    the direct indication of duration (1 s or 10 ms for example).
    New in version 23
    the direct indication of duration (1 s or 10 ms for example).
    the direct indication of duration (1 s or 10 ms for example).
This time-out is set to 5000 milliseconds by default (5 seconds). See remarks for more details.
PHP This parameter is ignored.
Versions 22 and later
WEBDEV - Browser code

Connecting to a WebSocket Hide the details

SocketConnect(<Socket Name> , <Address> , <Name of Browser Procedure> [, <Protocol(s)>])
<Socket Name>: Character string (with quotes)
Name that will be given when connecting to the server. This name will be used by all socket functions. Caution: The socket name is case sensitive.
<Address>: Character string (with quotes)
Address of the WebSockets server that will be used for the connection. This address has the following format: ws[s]://server[:port][/directoryX/.../]. In this case:
  • the ws prefix indicates that the server is a WebSockets server. wss is used for a secure WebSockets server.
  • server corresponds to the server address in the following format: server name, domain name or IP address of server.
  • port corresponds to the number of the communication port used to dialog with the server. This number must be identical to the port number specified in SocketCreate if the WebSockets server was created in WLanguage with WINDEV or WEBDEV.
  • directoryX corresponds to the possible virtual directories of server.
<Name of Browser Procedure>: Character string (with or without quotes)
Name of WLanguage procedure written in browser code ("callback" procedure). Name of procedure called when the connection to the server is established. This procedure is used to send a message to the server with SocketWrite.
This procedure has the following format:
PROCEDURE <Procedure Name>(<Event>, <Message>)

where:
  • <Event> corresponds to one of the following constants:
    SocketOpeningThe socket is connected to the server. You have the ability to send messages.
    SocketClosingThe socket is closed. The <Message> parameter is always empty.The <Message> parameter contains a code that indicates the reason for closing.
    SocketErrorAn error occurred during the communication with the server. The <Message> parameter is always empty.
    SocketMessageThe socket received a message. The <Message> parameter contains data relative to the message.
  • <Message> corresponds to the message received in server response according to the <Event>.
Note: There is no need to pass parameters to this procedure. Indeed, these parameters are automatically filled.
<Protocol(s)>: Character string (with quotes) or array of character strings (optional)
Protocol(s) corresponding to the format of WebSocket response. For example: "JSON", "XML". If this parameter is not specified or if it corresponds to an empty string, no protocol is used.
New in version 22
WEBDEV - Browser code

Connecting to a WebSocket Hide the details

SocketConnect(<Socket Name> , <Address> , <Name of Browser Procedure> [, <Protocol(s)>])
<Socket Name>: Character string (with quotes)
Name that will be given when connecting to the server. This name will be used by all socket functions. Caution: The socket name is case sensitive.
<Address>: Character string (with quotes)
Address of the WebSockets server that will be used for the connection. This address has the following format: ws[s]://server[:port][/directoryX/.../]. In this case:
  • the ws prefix indicates that the server is a WebSockets server. wss is used for a secure WebSockets server.
  • server corresponds to the server address in the following format: server name, domain name or IP address of server.
  • port corresponds to the number of the communication port used to dialog with the server. This number must be identical to the port number specified in SocketCreate if the WebSockets server was created in WLanguage with WINDEV or WEBDEV.
  • directoryX corresponds to the possible virtual directories of server.
<Name of Browser Procedure>: Character string (with or without quotes)
Name of WLanguage procedure written in browser code ("callback" procedure). Name of procedure called when the connection to the server is established. This procedure is used to send a message to the server with SocketWrite.
This procedure has the following format:
PROCEDURE <Procedure Name>(<Event>, <Message>)

where:
  • <Event> corresponds to one of the following constants:
    SocketOpeningThe socket is connected to the server. You have the ability to send messages.
    SocketClosingThe socket is closed. The <Message> parameter is always empty.The <Message> parameter contains a code that indicates the reason for closing.
    SocketErrorAn error occurred during the communication with the server. The <Message> parameter is always empty.
    SocketMessageThe socket received a message. The <Message> parameter contains data relative to the message.
  • <Message> corresponds to the message received in server response according to the <Event>.
Note: There is no need to pass parameters to this procedure. Indeed, these parameters are automatically filled.
<Protocol(s)>: Character string (with quotes) or array of character strings (optional)
Protocol(s) corresponding to the format of WebSocket response. For example: "JSON", "XML". If this parameter is not specified or if it corresponds to an empty string, no protocol is used.
WEBDEV - Browser code

Connecting to a WebSocket Hide the details

SocketConnect(<Socket Name> , <Address> , <Name of Browser Procedure> [, <Protocol(s)>])
<Socket Name>: Character string (with quotes)
Name that will be given when connecting to the server. This name will be used by all socket functions. Caution: The socket name is case sensitive.
<Address>: Character string (with quotes)
Address of the WebSockets server that will be used for the connection. This address has the following format: ws[s]://server[:port][/directoryX/.../]. In this case:
  • the ws prefix indicates that the server is a WebSockets server. wss is used for a secure WebSockets server.
  • server corresponds to the server address in the following format: server name, domain name or IP address of server.
  • port corresponds to the number of the communication port used to dialog with the server. This number must be identical to the port number specified in SocketCreate if the WebSockets server was created in WLanguage with WINDEV or WEBDEV.
  • directoryX corresponds to the possible virtual directories of server.
<Name of Browser Procedure>: Character string (with or without quotes)
Name of WLanguage procedure written in browser code ("callback" procedure). Name of procedure called when the connection to the server is established. This procedure is used to send a message to the server with SocketWrite.
This procedure has the following format:
PROCEDURE <Procedure Name>(<Event>, <Message>)

where:
  • <Event> corresponds to one of the following constants:
    SocketOpeningThe socket is connected to the server. You have the ability to send messages.
    SocketClosingThe socket is closed. The <Message> parameter is always empty.The <Message> parameter contains a code that indicates the reason for closing.
    SocketErrorAn error occurred during the communication with the server. The <Message> parameter is always empty.
    SocketMessageThe socket received a message. The <Message> parameter contains data relative to the message.
  • <Message> corresponds to the message received in server response according to the <Event>.
Note: There is no need to pass parameters to this procedure. Indeed, these parameters are automatically filled.
<Protocol(s)>: Character string (with quotes) or array of character strings (optional)
Protocol(s) corresponding to the format of WebSocket response. For example: "JSON", "XML". If this parameter is not specified or if it corresponds to an empty string, no protocol is used.
Remarks
WINDEVWEBDEV - Server codeReports and QueriesWindows MobileJavaUser code (UMC)

Optimizing the connections for an IP address

When an IP address is passed to SocketConnect, the connection can be optimized by using the following code:
Socket.Option = SocketOptimizeIPConnection
This option is not enabled by default because the connection may fail in some configurations. However, it may be useful in some applications for which the performances are critical.
Note: To restore the default operating mode, all you have to do is use the SocketOptionDefault constant:
Socket.Option = SocketOptionDefault
WINDEVWEBDEV - Server codeAndroidAndroid Widget iPhone/iPadWindows MobileJava

Time-out

The time-out specified by <Maximum Time-out> groups the time-out of two steps:
  • the time-out for address resolution: this time-out cannot be configured and it can be optimized (see below).
  • the maximum time-out for the connection to be accepted by the server. Several cases may occur:
    • the server refuses the connection.
    • the server accepts the connection within the time-out.
    • the server is not available.
    • the specified address is invalid.
To optimize the time-out for address resolution (time required to find the address), we advise you to:
  • use a DNS on the network. Therefore, this address will be sought toward this server and not for each computer (1 search instead of x searches where x represents the number of computers). Each computer must be registered toward this server.
  • for an IP address, use the Socket.Option variable as follows:
    Socket.Option = SocketOptimizeIPConnection
    iPhone/iPad This solution is not available.
WINDEVReports and QueriesWindows MobileUser code (UMC)

Connecting to an infrared port

To connect to a socket that is using an infrared port:
  1. Create a socket using the infrared port on the server (SocketCreateInfrared in a WINDEV application).
  2. In the client application (WINDEV application), use SocketConnectInfrared to connect to this socket.
AndroidAndroid Widget

Name resolution

The Android emulator does not use the system of name resolution of the computer on which it is run. This detail is important if your development computer is configured to automatically add a suffix of domain name local to the computer names to resolve. In the Android emulator, the full names must be specified.
For example: If your computer is configured to add the "mydomain.com" suffix to the simple names, the following code:
SocketConnect("myserver")
will attempt to connect to myserver.mydomain.com if it is run directly on the PC and to "myserver" in the Android emulator.
AndroidAndroid Widget

Required permissions

The call to this function modifies the permissions required by the application.
Required permission : INTERNET
This permission allows the applications to open the network sockets.
Versions 23 and later
Universal Windows 10 App

Required application feature

The use of this function triggers the declaration of an application feature in the wizard for generating the application.
Required feature: Family and corporate networks
This feature allows the applications to use incoming and outgoing accesses to the family and corporate networks.
New in version 23
Universal Windows 10 App

Required application feature

The use of this function triggers the declaration of an application feature in the wizard for generating the application.
Required feature: Family and corporate networks
This feature allows the applications to use incoming and outgoing accesses to the family and corporate networks.
Universal Windows 10 App

Required application feature

The use of this function triggers the declaration of an application feature in the wizard for generating the application.
Required feature: Family and corporate networks
This feature allows the applications to use incoming and outgoing accesses to the family and corporate networks.
Components
WINDEVWEBDEV - Server codeReports and Queries wd230com.dll
Windows Mobile wp230com.dll
WEBDEV - Browser code WDJS.DLL
Java wd230java.jar
Linux wd230com.so
Android wd230android.jar
Minimum required version
  • Version 9
This page is also available for…
Comments
Linux
Does not work on linux, run in a procedure.
Marcos
Jan. 04 2017