NetworkConnection

Package: Libraries.Network · Inherits from: Libraries.Language.Object

This class is used to manage a connection to a server using the internet protocol. More information on the internet protocol, called Hyper Text Transfer Protocol (HTTP) can be found at: https://www.w3.org/Protocols/.

Example Code

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequest
use Libraries.Network.NetworkResponseEvent
use Libraries.Network.NetworkRequestListener

class Main is NetworkRequestListener
action Main
    NetworkRequest request
    request:SetRequestTypeToGet()
    request:SetWebAddress("https://quorumlanguage.com/GETtest.php")
    NetworkConnection http
    http:AddListener(me)
    http:SendRequest(request)
end

action ResponseReceived(NetworkResponseEvent response)
    output response:GetResponseText()
end
end

Actions

AddListener(Libraries.Network.NetworkRequestListener listener)

This action adds a NetworkRequestListener to the connection which will be notified when the response returns.

Parameters

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequestListener
use Libraries.Network.NetworkResponseEvent

class Main is NetworkRequestListener
    action Main
        NetworkConnection http
        http:AddListener(me)
    end

    action ResponseReceived(NetworkResponseEvent response)
        // do something with the response
    end
end

GetListenerIterator()

This action returns a list of NetworkRequestListeners attached to the connection.

Returns

Libraries.Containers.Iterator<Libraries.Network.NetworkRequestListener>: An iterator to the list of NetworkRequestListeners.

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequestListener
use Libraries.Network.NetworkResponseEvent
use Libraries.Containers.Iterator

class Main is NetworkRequestListener
    action Main
        NetworkConnection http
        http:AddListener(me)
        Iterator<NetworkRequestListener> list = http:GetListenerIterator()
    end

    action ResponseReceived(NetworkResponseEvent response)
        // do something with the response
    end
end

GetNetworkRequest()

This action sends a network request over the connection in the object.

Returns

Libraries.Network.NetworkRequest: The NetworkRequest.

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequest
use Libraries.Network.NetworkResponseEvent
use Libraries.Network.NetworkRequestListener

class Main is NetworkRequestListener
    action Main
        NetworkRequest request
        request:SetRequestTypeToGet()
        request:SetWebAddress("https://quorumlanguage.com/GETtest.php")
        NetworkConnection http
        http:AddListener(me)
        http:SendRequest(request)
        NetworkRequest copy
        copy = http:GetNetworkRequest()
    end

    action ResponseReceived(NetworkResponseEvent response)
        output response:GetResponseText()
    end
end

GetNewResponseEvent()

This action returns a new NetworkResponseEvent.

Returns

Libraries.Network.NetworkResponseEvent: The NetworkResponseEvent.

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkResponseEvent

class Main
    action Main
        NetworkConnection http
        NetworkResponseEvent response = http:GetNewResponseEvent()
    end
end

GetServerNameIdentification()

This action retrieves the value of the ServerNameIdentification (SNI) check for Quorum using the desktop. The default value is true. See the SetServerNameIdentification action for a further description.

Returns

boolean: value The value of the SNI setting for the connection.

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequest
use Libraries.Network.NetworkResponseEvent
use Libraries.Network.NetworkRequestListener

class Main is NetworkRequestListener
    action Main
        NetworkRequest request
        request:SetRequestTypeToGet()
        request:SetWebAddress("https://quorumlanguage.com/GETtest.php")
        NetworkConnection http
        output http:GetServerNameIdentification()
        http:AddListener(me)
        http:SendRequest(request)
        NetworkRequest copy
        copy = http:GetNetworkRequest()
    end

    action ResponseReceived(NetworkResponseEvent response)
        output response:GetResponseText()
    end
end

Notify(integer length, integer read)

This action notifies the listeners with the amount of data that has been processed toward a download.

Parameters

  • length integer: the total size of the download in bytes
  • read integer: the total amount of data that has been read so far in bytes

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequestListener
use Libraries.Network.NetworkResponseEvent
use Libraries.Containers.Iterator

class Main is NetworkRequestListener
    action Main
        NetworkConnection http
        http:AddListener(me)
        http:Notify(0,1)
    end

    action ResponseReceived(NetworkResponseEvent response)
        output response:GetResponseText()
    end

    action DownloadProgress(integer length, integer read)
        output legnth + " of " + read
    end
end

Notify(Libraries.Network.NetworkResponseEvent response)

This action notifies the listeners with the response event.

Parameters

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequestListener
use Libraries.Network.NetworkResponseEvent
use Libraries.Containers.Iterator

class Main is NetworkRequestListener
    action Main
        NetworkConnection http
        http:AddListener(me)
        NetworkResponseEvent response = http:GetNewResponseEvent()
        response:SetResponseText("Hello world!")
        http:Notify(response)
    end

    action ResponseReceived(NetworkResponseEvent response)
        output response:GetResponseText()
    end
end

RemoveListener(Libraries.Network.NetworkRequestListener listener)

This action adds a NetworkRequestListener to the connection which will be notified when the response returns.

Parameters

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequestListener
use Libraries.Network.NetworkResponseEvent

class Main is NetworkRequestListener
    action Main
        NetworkConnection http
        http:AddListener(me)
        http:RemoveListener(me)
    end

    action ResponseReceived(NetworkResponseEvent response)
        // do something with the response
    end
end

SendRequest(Libraries.Network.NetworkRequest request)

This action sends a Network request over the connection in the object.

Parameters

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequest
use Libraries.Network.NetworkResponseEvent
use Libraries.Network.NetworkRequestListener

class Main is NetworkRequestListener
    action Main
        NetworkRequest request
        request:SetRequestTypeToGet()
        request:SetWebAddress("https://quorumlanguage.com/GETtest.php")
        NetworkConnection http
        http:AddListener(me)
        http:SendRequest(request)
    end

    action ResponseReceived(NetworkResponseEvent response)
        output response:GetResponseText()
    end
end

SetDownloadProgress(integer length, integer read)

This action sets a response event indicating progress toward a download.

Parameters

  • length integer
  • read integer

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequestListener
use Libraries.Network.NetworkResponseEvent
use Libraries.Containers.Iterator

class Main is NetworkRequestListener
    action Main
        NetworkConnection http
        http:AddListener(me)
        http:SetDownloadProgress(0,1)
    end

    action ResponseReceived(NetworkResponseEvent response)
        output response:GetResponseText()
    end

    action DownloadProgress(integer length, integer read)
        output legnth + " of " + read
    end
end

SetResponse(Libraries.Network.NetworkResponseEvent response)

This action sets a response event in the connection object and notifies the listeners.

Parameters

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequestListener
use Libraries.Network.NetworkResponseEvent
use Libraries.Containers.Iterator

class Main is NetworkRequestListener
    action Main
        NetworkConnection http
        http:AddListener(me)
        NetworkResponseEvent response = http:GetNewResponseEvent()
        response:SetResponseText("Hello world!")
        http:SetResponse(response)
    end

    action ResponseReceived(NetworkResponseEvent response)
        output response:GetResponseText()
    end
end

SetServerNameIdentification(boolean value)

This action enables or disables the ServerNameIdentification (SNI) extension in Java for Quorum using the desktop. SNI is a security feature that checks if the name of the web server you are accessing matches the name on its authentication certificate. Normally you should keep this setting on the default (which is true), but many third party web servers are misconfigured and require a work around. If you receive an error when trying to connect such as "SSLProtocolException: handshake alert: unrecognized_name" you can set this to false and it will bypass the warning and connect anyway. Note that this only affects the java plugin on the desktop and does not affect the connection through the JavaScript plugin used by the online interactive development environment.

Parameters

  • value boolean: A boolean setting to enable or disable the SNI extension in Java.

Example

use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequest
use Libraries.Network.NetworkResponseEvent
use Libraries.Network.NetworkRequestListener

class Main is NetworkRequestListener
    action Main
        NetworkRequest request
        request:SetRequestTypeToGet()
        request:SetWebAddress("https://quorumlanguage.com/GETtest.php")
        NetworkConnection http
        http:SetServerNameIdentification(false)
        http:AddListener(me)
        http:SendRequest(request)
        NetworkRequest copy
        copy = http:GetNetworkRequest()
    end

    action ResponseReceived(NetworkResponseEvent response)
        output response:GetResponseText()
    end
end

Inherited Actions

3 actions from Libraries.Language.Object