+ All Categories
Home > Documents > MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains:...

MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains:...

Date post: 03-Jul-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
26
MBS Xojo Network Kit Version 1.1, © 2015 - 2019 by Christian Schmitz About the MBS Xojo Network Kit 2 NSConnection Wrapper 3 NSNetService Wrapper 4 Interfaces 5 NetworkKitUtilityModule 5 NSNetServiceBrowserMB 6 NSNetServiceMB 7 NSErrorMB 9 NSURLConnectionMB 10 NSURLRequestMB 11 NSMutableURLRequestMB 15 NSURLResponseMB 18 NSURLConnectionMemoryMB 20 NSURLConnectionFileMB 21 Version History 22 Known issues 22 Installation 23 Requirements 24 License 25 Contact 26 Network Kit Manual, Page of 1 26
Transcript
Page 1: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

MBS Xojo Network Kit

Version 1.1, © 2015 - 2019 by Christian Schmitz

About the MBS Xojo Network Kit 2

NSConnection Wrapper 3

NSNetService Wrapper 4

Interfaces 5

NetworkKitUtilityModule 5

NSNetServiceBrowserMB 6

NSNetServiceMB 7

NSErrorMB 9

NSURLConnectionMB 10

NSURLRequestMB 11

NSMutableURLRequestMB 15

NSURLResponseMB 18

NSURLConnectionMemoryMB 20

NSURLConnectionFileMB 21

Version History 22

Known issues 22

Installation 23

Requirements 24

License 25

Contact 26

Network Kit Manual, Page � of �1 26

Page 2: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

About the MBS Xojo Network KitThe MBS Xojo Network Kit provides you with a few useful classes and modules to easily use network functions in iOS.

The Kit contains:

• Wrapper for OS X and iOS Bonjour classes to publish service and browser for service including resolving the IP addresses.

• Wrapper for OS X and iOS for NSConnection classes including NSURLRequest/NSURLResponse with HTTP extensions.

• Common code for Cocoa base classes in the NetworkKitUtilityModule module.

Network Kit Manual, Page � of �2 26

Page 3: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSConnection WrapperThe Network Kit contains a wrapper for NSConnection, Apple's Cocoa interface for download on OS X and iOS:

Features

• HTTP and HTTPS support.• FTP download support• Synchronously and asynchronously transfers• Load to memory or file• Supply HTTP Header fields• Supply HTTP Body for upload• Supply HTTP Method like GET, PUT, POST or others.• Control about cache handling• Can use pipelining with HTTP 1.1• Define if to use cellular network or not.

Wrapper Features

• For Xojo 2015r1• Using exception handling to track error• Test code included• All classes with MB postfix to avoid name conflicts.• Compiles for all targets• All module definitions are protected to avoid conflicts• Inline documentation• Full Source code, no encryption• Works for 32bit and 64bit targets.• Example projects for Desktop, iOS and Console using our classes.

Future features we could add:

• Support for password authentication.• Add NSURLSession classes.

Network Kit Manual, Page � of �3 26

Page 4: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSNetService WrapperThe Network Kit contains a wrapper for NSNetService and NSNetServiceBrowser, Apple's Cocoa interface for Bonjour on OS X and iOS:

Features

• asynchronously browses for domains to use• asynchronously browses for services with given type• asynchronously publishes services• query/publish TXT Record data.• Function to check for events on console projects.• Parse code for IP addresses, supporting IPv4 and IPv6

Wrapper Features

• For Xojo 2015r1• Using exception handling to track error• Test code included• All classes with MB postfix to avoid name conflicts.• Compiles for all targets• All module definitions are protected to avoid conflicts• Inline documentation• Full Source code, no encryption• Works for 32bit and 64bit targets.• Example projects for Desktop, Web, iOS and Console using our classes.

Future features we could add:

• TXT Record parse/create functions.• didAcceptConnectionWithInputStreamOutputStream event

Network Kit Manual, Page � of �4 26

Page 5: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

InterfacesNetworkKitUtilityModule

Module NetworkKitUtilityModuleProtected Sub AddToDelegateMap(handle as integer, o as object)Protected Function AllocateObject(ClassRef as Integer) As integerProtected Sub CheckEvents()

for console onlyruns runloop for one round to check for events

Protected Sub CheckForMainThread()Protected Sub CheckRunLoop(ServiceHandle as integer)Protected Function ClassName(handle as integer) As Text

get class name of a handleProtected Function GetEmpyNSStringHandle() As IntegerProtected Function GetInstanceForHandle(Handle as Integer) As ObjectProtected Function Init(handle as integer) As integerProtected Function IsTextVariant(v as Variant) As BooleanProtected Function MemoryBlockCStringToText(m as memoryblock) As textProtected Function MemoryBlockToNSData(m as MemoryBlock) As integerProtected Function MemoryBlockToPtr(m as memoryblock) As ptrProtected Function NSClassFromText(Name as Text) As IntegerProtected Function NSDataLength(NSDataRef as Integer) As UInt64Protected Function NSDataToMemoryBlock(NSDataRef as Integer) As MemoryBlockProtected Function NSDataToString(NSDataRef as Integer) As stringProtected Function NSDictionaryFromDictionary(dic as Dictionary) As Integer

converts Dictionary with only Text/String to NSDictionaryProtected Function NSDictionaryFromDictionary(dic as xojo.Core.Dictionary) As Integer

converts Dictionary with only Text/String to NSDictionaryProtected Function NSDictionaryToDictionary(NSDictionaryRef as Integer) As Dictionary

converts Dictionary with only NSString to Xojo DictionaryProtected Function NSInputStreamFromPath(Path as String) As IntegerProtected Function NSInputStreamFromPath(Path as Text) As IntegerProtected Function NSInputStreamFromURL(URL as Text) As IntegerProtected Function NSInputStreamFromURL(URL as string) As IntegerProtected Function NSSelectorFromString(Name as string) As IntegerProtected Function NSSelectorFromText(Name as Text) As IntegerProtected Function NSURLFromText(URL as String) As IntegerProtected Function NSURLFromText(URL as Text) As IntegerProtected Function NSURLPath(NSURLHandle as integer) As textProtected Function NSURLToText(NSURLHandle as integer) As textProtected Sub ReleaseHandle(handle as integer)Protected Sub RemoveFromDelegateMap(handle as integer)Protected Function RetainCount(Handle as Integer) As integerProtected Function RetainHandle(handle as integer) As integerProtected Function TextToMemoryBlock(t as text) As memoryblock

End Module

Network Kit Manual, Page � of �5 26

Page 6: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSNetServiceBrowserMB

Class NSNetServiceBrowserMBComputedProperty Description As text

Sub Get()description for debugging

ComputedProperty includesPeerToPeer As BooleanSub Set()

Initially set to false.Set to true to also browse over peer to peer Bluetooth and Wi-Fi (if available).Must be set before starting to search.

Sub Get()Initially set to false.Set to true to also browse over peer to peer Bluetooth and Wi-Fi (if available).Must be set before starting to search.

Const NSNetServicesActivityInProgress = -72003Const NSNetServicesBadArgumentError = -72004Const NSNetServicesCancelledError = -72005Const NSNetServicesCollisionError = -72001Const NSNetServicesInvalidError = -72006Const NSNetServicesNotFoundError = -72002Const NSNetServicesTimeoutError = -72007Const NSNetServicesUnknownError = -72000Sub CheckEvents()

for console onlyruns runloop for one round to check for events

Sub Constructor()Sub Constructor(Handle as Integer)Sub Destructor()Sub searchForBrowsableDomains()

Starts a search for domains that are browsable via Bonjour and the computer's network configuration.Discovered domains are reported to the DidFindDomain event. There may be more than one browsable

domain.Sub searchForRegistrationDomains()

Starts a search for domains in which the network configuration allows registration (i.e. publishing).Most NSNetServiceBrowser clients do not need to use this API, as it is sufficient to publish an

NSNetServiceinstance with the empty string (see -[NSNetService initWithDomain:type:name:port:]).Discovered domains are reported to the DidFindDomain event.There may be more than one registration domain.

Sub searchForServicesOfType(type as text, domain as text = "")Starts a search for services of the specified type in the domain indicated by domainString.For each service discovered, a foundService event is raised.

Sub stop()Stops the currently running search.

End Class

Network Kit Manual, Page � of �6 26

Page 7: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSNetServiceMB

Class NSNetServiceMBComputedProperty Description As text

Sub Get()ComputedProperty TXTRecordData As MemoryBlock

Sub Set()Sets the TXT record of the NSNetService instance that has been or will be published.Pass nil to remove the TXT record from the instance.

Sub Get()Returns the raw TXT record of the NSNetService instance.If the instance has not been resolved, or the DidUpdateTXTRecordData event has not been

called, this will return nil.It is permitted to have a zero-length TXT record.

ComputedProperty addressIPv4 As textSub Get()

get first IPv4 addressComputedProperty addressIPv6 As text

Sub Get()get first IPv6 address

ComputedProperty className As textSub Get()

ComputedProperty domain As textSub Get()

Returns the domain of the discovered or published service.ComputedProperty hostName As text

Sub Get()Returns the DNS host name of the computer hosting the discovered or published service.If a successful resolve has not yet occurred, this method will return "".

ComputedProperty includesPeerToPeer As BooleanSub Set()

Initially set to false.Set to true to also publish, resolve, or monitor this service over peer to peer Bluetooth and

Wi-Fi (if available).Must be set before operation starts.

Sub Get()Initially set to false.Set to true to also publish, resolve, or monitor this service over peer to peer Bluetooth and

Wi-Fi (if available).Must be set before operation starts.

ComputedProperty name As textSub Get()

Returns the name of the discovered or published service.ComputedProperty port As Integer

Sub Get()The port of a resolved service. This returns -1 if the service has not been resolved.

ComputedProperty type As textSub Get()

Returns the type of the discovered or published service.Const NSNetServiceListenForConnections = 2Const NSNetServiceNoAutoRename = 1Const NSNetServicesActivityInProgress = -72003Const NSNetServicesBadArgumentError = -72004Const NSNetServicesCancelledError = -72005Const NSNetServicesCollisionError = -72001Const NSNetServicesInvalidError = -72006Const NSNetServicesNotFoundError = -72002Const NSNetServicesTimeoutError = -72007Const NSNetServicesUnknownError = -72000Sub CheckEvents()

for console onlyruns runloop for one round to check for events

Sub Constructor(Handle as Integer)init with handle

Sub Constructor(s as NSNetServiceMB)put an existing service in a new object, e.g. to handle events

Network Kit Manual, Page � of �7 26

Page 8: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

Sub Constructor(domain as text, type as text, name as text)This is the initializer for resolution.If you know the domain, type and name of the service for which you wish to discover addresses,you should initialize an NSNetService instance using this method and call resolve on the result.

Sub Constructor(domain as text, type as text, name as text, port as integer)This is the initializer for publishing.You should use this initializer if you are going to announce the availability of a service on the network.To publish a service in all available domains, pass the empty string as the domain.

Sub Destructor()Function addresses(IPv4 as Boolean = true, IPv6 as Boolean = true) As text()

The addresses of the service.pass IPv4 or IPv6 as false to filter list

Sub publish()Advertises a given service on the network.This method returns immediately. Success or failure is indicated by callbacks to the NSNetService

instance's delegate.Sub publish(options as integer)

Advertises a given service on the network.This method returns immediately. Success or failure is indicated by callbacks to the NSNetService

events.

See the notes above for NSNetServiceNoAutoRename for information about controlling the auto-renaming

behavior using this method.Sub resolve()

Attempts to determine at least one address for the NSNetService instance.For applications linked on or after Mac OS X 10.4 "Tiger", this method callsresolveWithTimeout with a value of 5.0.

Sub resolve(timeout as Double)Starts a resolve for the NSNetService instance of the specified duration.If the DidResolveAddress event is called before the timeout expires, the resolve is successful.If the timeout is reached, the DidNotResolve event will be called.The value of the NSNetServicesErrorCode key in the error dictionary will be

NSNetServicesTimeoutError.Sub startMonitoring()

Starts monitoring the NSNetService instance for events.In Mac OS X 10.4 Tiger, monitored NSNetService instances inform their delegates of changes to the

instance's TXT record by calling the DidUpdateTXTRecordData event.Sub stop()

Halts a service which is either publishing or resolving.Sub stopMonitoring()

Stops monitoring the NSNetService instance for events.Property Handle As Integer

End Class

Network Kit Manual, Page � of �8 26

Page 9: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSErrorMB

Class NSErrorMBComputedProperty code As integer

Sub Get()get error code

ComputedProperty domain As textSub Get()

get error domainComputedProperty localizedDescription As text

Sub Get()get localized error description

Sub Constructor(Handle as Integer)Sub Destructor()Property Handle As Integer

End Class

Network Kit Manual, Page � of �9 26

Page 10: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSURLConnectionMB

Class NSURLConnectionMBComputedProperty currentRequest As NSURLRequestMB

Sub Get()new in Mac OS X 10.8 and iOS 5.0

ComputedProperty originalRequest As NSURLRequestMBSub Get()

new in Mac OS X 10.8 and iOS 5.0Sub Destructor()

cleanupShared Function canHandleRequest(request as NSURLRequestMB) As BooleanSub cancel()

cancel transferShared Function sendSynchronousRequest(request as NSURLRequestMB, byref response as

NSURLResponseMB, byref Error as NSErrorMB) As MemoryBlockPerforms a synchronous load of the given request,returning an NSURLResponse in the given outparameter.

Sub start()starts transfer

Note "About"This is the base class for NSURLConnection.

Property Handle As IntegerProperty IsLoading As BooleanProperty TotalSize As Int64Property done As Boolean

End Class

Network Kit Manual, Page � of �10 26

Page 11: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSURLRequestMB

Class NSURLRequestMBComputedProperty HTTPBody As MemoryBlock

Sub Get()Returns the request body data of the receiver.This data is sent as the message body of the request, as in done in an HTTP POST request.The request body data of the receiver.

ComputedProperty HTTPMethod As textSub Get()

Returns the HTTP request method of the receiver.ComputedProperty HTTPShouldHandleCookies As Boolean

Sub Get()Decide whether default cookie handling will happen for this request.True if cookies should be sent with and set for this request; otherwise false.The default is true - in other words, cookies are sent from andstored to the cookie manager by default.

ComputedProperty HTTPShouldUsePipelining As BooleanSub Get()

Reports whether the receiver is not expected to wait for theprevious response before transmitting.True if the receiver should transmit before the previous responseis received. False if the receiver should wait for the previous responsebefore transmitting.

ComputedProperty TimeoutInterval As doubleSub Get()

get timeout in secondsComputedProperty URL As text

Sub Get()Returns the URL of the receiver.

ComputedProperty allHTTPHeaderFields As DictionarySub Get()

Queries the HTTP header fields of the receiver to the given dictionary.This method replaces all header fields that may have existed before this method call.Since HTTP header fields must be string values, each object andkey in the dictionary passed to this method must be text. If eitherthe key or value for a key-value pair is not text when sent thismessage, the key-value pair is skipped.

ComputedProperty allowsCellularAccess As BooleanSub Get()

returns whether a connection created with this request is allowed to usethe built in cellular radios (if present).True if the receiver is allowed to use the built in cellular radios tosatify the request, false otherwise.

ComputedProperty cachePolicy As NSURLRequestCachePolicySub Get()

Returns the cache policy of the receiver.ComputedProperty mainDocumentURL As text

Sub Get()The main document URL associated with this load.This URL is used for the cookie "same domain as main document" policy. There may also be

other future uses.See setting MainDocumentURLIn the current implementation, this value is unused by theframework. A fully functional version of this method will be availablein the future.

ComputedProperty networkServiceType As NSURLRequestNetworkServiceTypeSub Get()

Returns the NSURLRequestNetworkServiceType associated with this request.This will return NSURLNetworkServiceTypeDefault for requests that havenot explicitly set a networkServiceType (using the NetworkServiceType setter).The NSURLRequestNetworkServiceType associated with this request.

Enum NSURLRequestCachePolicyNSURLRequestUseProtocolCachePolicy = 0NSURLRequestReloadIgnoringLocalCacheData = 1NSURLRequestReturnCacheDataElseLoad = 2

Network Kit Manual, Page � of �11 26

Page 12: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSURLRequestReturnCacheDataDontLoad = 3NSURLRequestReloadIgnoringCacheData = 1

End EnumEnum NSURLRequestNetworkServiceType

NSURLNetworkServiceTypeDefault = 0NSURLNetworkServiceTypeVoIP = 1NSURLNetworkServiceTypeVideo = 2NSURLNetworkServiceTypeBackground = 3NSURLNetworkServiceTypeVoice = 4

End EnumSub Constructor(Handle as Integer)

create request with given handleSub Constructor(URL as text)

Allocates and initializes an NSURLRequest with the given URL.Default values are used for cache policy (NSURLRequestUseProtocolCachePolicy) and timeout

interval (60 seconds).Sub Constructor(URL as text, cachePolicy as NSURLRequestCachePolicy, timeoutInterval as Double)

Allocates and initializes a NSURLRequest with the given URL and cache policy.Sub Destructor()Shared Function Tests() As MemoryBlock

some tests if things work in generalFunction copy() As NSURLRequestMB

creates a copy of the requestFunction mutableCopy() As NSMutableURLRequestMB

Creates a mutable copy of this requestShared Sub testMessage(s as text)Function valueForHTTPHeaderField(field as text) As text

Returns the value which corresponds to the given headerfield. Note that, in keeping with the HTTP RFC, HTTP header fieldnames are case-insensitive.field the header field name to use for the lookup (case-insensitive).the value associated with the given header field, or empty text ifthere is no value associated with the given header field.

Note "About"NSURLRequest

This class file describes the constructs used to represent URLload requests in a manner independent of protocol and URL scheme.Immutable and mutable variants of this URL load request conceptare described, named NSURLRequest and NSMutableURLRequest,respectively. A collection of constants is also declared toexercise control over URL content caching policy.

NSURLRequest and NSMutableURLRequest are designed to becustomized to support protocol-specific requests.

enum NSURLRequestCachePolicy

The NSURLRequestCachePolicy enum defines constants thatcan be used to specify the type of interactions that take place withthe caching system when the URL loading system processes a request.Specifically, these constants cover interactions that have to dowith whether already-existing cache data is returned to satisfy aURL load request.

NSURLRequestUseProtocolCachePolicy Specifies that thecaching logic defined in the protocol implementation, if any, isused for a particular URL load request. This is the default policyfor URL load requests.

NSURLRequestReloadIgnoringLocalCacheData Specifies that thedata for the URL load should be loaded from the origin source. Noexisting local cache data, regardless of its freshness or validity,should be used to satisfy a URL load request.

Network Kit Manual, Page � of �12 26

Page 13: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSURLRequestReloadIgnoringLocalAndRemoteCacheData Specifies thatnot only should the local cache data be ignored, but that proxies andother intermediates should be instructed to disregard their cachesso far as the protocol allows. Unimplemented.

NSURLRequestReloadIgnoringCacheData Older name forNSURLRequestReloadIgnoringLocalCacheData.

NSURLRequestReturnCacheDataElseLoad Specifies that theexisting cache data should be used to satisfy a URL load request,regardless of its age or expiration date. However, if there is noexisting data in the cache corresponding to a URL load request,the URL is loaded from the origin source.

NSURLRequestReturnCacheDataDontLoad Specifies that theexisting cache data should be used to satisfy a URL load request,regardless of its age or expiration date. However, if there is noexisting data in the cache corresponding to a URL load request, noattempt is made to load the URL from the origin source, and theload is considered to have failed. This constant specifies abehavior that is similar to an "offline" mode.

@constant NSURLRequestReloadRevalidatingCacheData Specifies thatthe existing cache data may be used provided the origin sourceconfirms its validity, otherwise the URL is loaded from theorigin source. Unimplemented.

enum NSURLRequestNetworkServiceType

The NSURLRequestNetworkServiceType enum defines constants thatcan be used to specify the service type to associate with this request. Theservice type is used to provide the networking layers a hint of the purposeof the request.

NSURLNetworkServiceTypeDefault Is the default value for an NSURLRequestwhen created. This value should be left unchanged for the vast majority of requests.

NSURLNetworkServiceTypeVoIP Specifies that the request is for voice over IPcontrol traffic.

NSURLNetworkServiceTypeVideo Specifies that the request is for videotraffic.

NSURLNetworkServiceTypeBackground Specifies that the request is for backgroundtraffic (such as a file download).

NSURLNetworkServiceTypeVoice Specifies that the request is for voice data.

NSURLRequest

An NSURLRequest object represents a URL load request in amanner independent of protocol and URL scheme.

NSURLRequest encapsulates two basic data elements abouta URL load request:

* The URL to load.* The policy to use when consulting the URL content cache made available by the implementation.

In addition, NSURLRequest is designed to be extended to supportprotocol-specific data by adding categories to access a propertyobject provided in an interface targeted at protocol implementors.

Network Kit Manual, Page � of �13 26

Page 14: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

Objects of this class are used to create NSURLConnection instances,which can are used to perform the load of a URL, or as input to theNSURLConnection class method which performs synchronous loads.

Property Handle As IntegerEnd Class

Network Kit Manual, Page � of �14 26

Page 15: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSMutableURLRequestMB

Class NSMutableURLRequestMB Inherits NSURLRequestMBComputedProperty HTTPBody As MemoryBlock

Sub Set()Sets the request body data of the receiver.This data is sent as the message body of the request, as in done in an HTTP POST request.Value: the new request body data for the receiver.

Sub Get()Returns the request body data of the receiver.This data is sent as the message body of the request, as in done in an HTTP POST request.The request body data of the receiver.

ComputedProperty HTTPMethod As textSub Set()

Sets the HTTP request method of the receiver.Sub Get()

Returns the HTTP request method of the receiver.ComputedProperty HTTPShouldHandleCookies As Boolean

Sub Set()Decide whether default cookie handling will happen for this request.True if cookies should be sent with and set for this request; otherwise false.The default is true - in other words, cookies are sent from andstored to the cookie manager by default.

Sub Get()Decide whether default cookie handling will happen for this request.True if cookies should be sent with and set for this request; otherwise false.The default is true - in other words, cookies are sent from andstored to the cookie manager by default.

ComputedProperty HTTPShouldUsePipelining As BooleanSub Set()

Sets whether the request should not wait for the previous responsebefore transmitting.True if the receiver should transmit before the previous response isreceived. False to wait for the previous response before transmitting.Calling this method with a true value does not guarantee HTTPpipelining behavior. This method may have no effect if an HTTP proxy isconfigured, or if the HTTP request uses an unsafe request method (e.g., POSTrequests will not pipeline). Pipelining behavior also may not begin untilthe second request on a given TCP connection. There may be other situationswhere pipelining does not occur even though YES was set.HTTP 1.1 allows the client to send multiple requests to the server withoutwaiting for a response. Though HTTP 1.1 requires support for pipelining,some servers report themselves as being HTTP 1.1 but do not supportpipelining (disconnecting, sending resources misordered, omitting part ofa resource, etc.).

Sub Get()Reports whether the receiver is not expected to wait for theprevious response before transmitting.True if the receiver should transmit before the previous responseis received. False if the receiver should wait for the previous responsebefore transmitting.

ComputedProperty TimeoutInterval As DoubleSub Set()

Sets the timeout interval of the receiver.The timeout interval specifies the limit on the idleinterval allotted to a request in the process of loading. The "idleinterval" is defined as the period of time that has passed since thelast instance of load activity occurred for a request that is in theprocess of loading. Hence, when an instance of load activity occurs(e.g. bytes are received from the network for a request), the idleinterval for a request is reset to 0. If the idle interval everbecomes greater than or equal to the timeout interval, the requestis considered to have timed out. This timeout interval is measuredin seconds.value: The new timeout interval in seconds of the receiver.

Sub Get()Network Kit Manual, Page � of �15 26

Page 16: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

get timeout in secondsComputedProperty URL As text

Sub Set()Sets the URL of the receiver.

Sub Get()Returns the URL of the receiver.

ComputedProperty allHTTPHeaderFields As DictionarySub Set()

Sets the HTTP header fields of the receiver to the given dictionary.This method replaces all header fields that may have existed before this method call.Since HTTP header fields must be string values, each object andkey in the dictionary passed to this method must be text. If eitherthe key or value for a key-value pair is not text when sent thismessage, the key-value pair is skipped.value: a dictionary containing HTTP header fields.

Sub Get()Queries the HTTP header fields of the receiver to the given dictionary.This method replaces all header fields that may have existed before this method call.Since HTTP header fields must be string values, each object andkey in the dictionary passed to this method must be text. If eitherthe key or value for a key-value pair is not text when sent thismessage, the key-value pair is skipped.

ComputedProperty allowsCellularAccess As BooleanSub Set()

sets whether a connection created with this request is allowed to usethe built in cellular radios (if present).allow false if the receiver should not be allowed to use the built incellular radios to satisfy the request, true otherwise. The default is true.

Sub Get()returns whether a connection created with this request is allowed to usethe built in cellular radios (if present).True if the receiver is allowed to use the built in cellular radios tosatify the request, false otherwise.

ComputedProperty cachePolicy As NSURLRequestCachePolicySub Set()

sets the cache policy of the receiver.Sub Get()

Returns the cache policy of the receiver.ComputedProperty mainDocumentURL As text

Sub Set()Sets the main document URLURL The main document URL.The caller should pass the URL for an appropriate maindocument, if known. For example, when loading a web page, the URLof the main html document for the top-level frame should bepassed. This main document will be used to implement the cookie"only from same domain as main document" policy, and possiblyother things in the future.NOTE: In the current implementation, the passed-in value is unused by theframework. A fully functional version of this method will be availablein the future.

Sub Get()The main document URL associated with this load.This URL is used for the cookie "same domain as main document" policy. There may also be

other future uses.See setting MainDocumentURLIn the current implementation, this value is unused by theframework. A fully functional version of this method will be availablein the future.

ComputedProperty networkServiceType As NSURLRequestNetworkServiceTypeSub Set()

Sets the NSURLRequestNetworkServiceType to associate with this requestnetworkServiceType The NSURLRequestNetworkServiceType to associate with the request.This method is used to provide the network layers with a hint as to the purposeof the request. Most clients should not need to use this method.

Sub Get()

Network Kit Manual, Page � of �16 26

Page 17: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

Returns the NSURLRequestNetworkServiceType associated with this request.This will return NSURLNetworkServiceTypeDefault for requests that havenot explicitly set a networkServiceType (using the NetworkServiceType setter).The NSURLRequestNetworkServiceType associated with this request.

Sub Constructor()create new empty request

Sub Constructor(theHandle as Integer)create request with given handle

Sub Constructor(URL as text)Allocates and initializes an NSURLRequest with the given URL.Default values are used for cache policy (NSURLRequestUseProtocolCachePolicy) and timeout

interval (60 seconds).Sub Constructor(URL as text, cachePolicy as NSURLRequestCachePolicy, timeoutInterval as Double)

Allocates and initializes a NSURLRequest with the given URL and cache policy.Sub ValueForHTTPHeaderField(field as text, assigns value as text)

for assignment like this:x.ValueForHTTPHeaderField(Field) = value

Sub addValueForHTTPHeaderField(field as text, value as text)Adds an HTTP header field in the current header dictionary.This method provides a way to add values to headerfields incrementally. If a value was previously set for the givenheader field, the given value is appended to the previously-existingvalue. The appropriate field delimiter, a comma in the case of HTTP,is added by the implementation, and should not be added to the givenvalue by the caller. Note that, in keeping with the HTTP RFC, HTTPheader field names are case-insensitive.

Sub setHTTPBodyWithFile(file as FolderItem)Sets the request body to be the contents of the given file.The entire file's contents will be transmitted as the HTTP body of the request.Note that the body stream and the body data (set by HTTPBody) are mutually exclusivesetting one will clear the other.

Sub setHTTPBodyWithPath(Path as Text)Sets the request body to be the contents of the given file.The entire file's contents will be transmitted as the HTTP body of the request.Note that the body stream and the body data (set by HTTPBody) are mutually exclusivesetting one will clear the other.

Sub setHTTPBodyWithURL(URL as text)Sets the request body to be the contents of the given file.The entire file's contents will be transmitted as the HTTP body of the request.Note that the body stream and the body data (set by HTTPBody) are mutually exclusivesetting one will clear the other.

Sub setValueForHTTPHeaderField(field as text, value as text)Sets the value of the given HTTP header field.If a value was previously set for the given headerfield, that value is replaced with the given value. Note that, inkeeping with the HTTP RFC, HTTP header field names arecase-insensitive.

Note "About"class NSMutableURLRequest

An NSMutableURLRequest object represents a mutable URL loadrequest in a manner independent of protocol and URL scheme.

This specialization of NSURLRequest is provided to aiddevelopers who may find it more convenient to mutate a single requestobject for a series of URL loads instead of creating an immutableNSURLRequest for each load. This programming model is supported bythe following contract stipulation between NSMutableURLRequest andNSURLConnection: NSURLConnection makes a deep copy of eachNSMutableURLRequest object passed to one of its initializers.

End Class

Network Kit Manual, Page � of �17 26

Page 18: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSURLResponseMB

Class NSURLResponseMBComputedProperty MIMEType As text

Sub Get()Returns the MIME type of the receiver.The MIME type is based on the information providedfrom an origin source. However, that value may be changed orcorrected by a protocol implementation if it can be determinedthat the origin server or source reported the informationincorrectly or imprecisely. An attempt to guess the MIME type maybe made if the origin source did not report any such information.

ComputedProperty URL As textSub Get()

Returns the URL of the receiver.ComputedProperty allHeaderFields As Dictionary

Sub Get()Returns a dictionary containing all the HTTP header fields of the receiver.By examining this header dictionary, clients can see the "raw" header information which was

reported to the protocolimplementation by the HTTP server. This may be of use to sophisticated or special-purpose

HTTP clients.Returns a dictionary containing all the HTTP header fields of the receiver.

ComputedProperty expectedContentLength As Int64Sub Get()

Returns the expected content length of the receiver.ComputedProperty statusCode As Integer

Sub Get()Returns the HTTP status code of the receiver.

ComputedProperty suggestedFilename As textSub Get()

Returns a suggested filename if the resource were saved to disk.ComputedProperty textEncodingName As text

Sub Get()Returns the name of the text encoding of the receiver.

Sub Constructor(Handle as Integer)create new response with given handle

Sub Constructor(URL as text, StatusCode as Integer, HTTPVersion as Text, HeaderFields as Dictionary)Initializer for NSHTTPURLResponse objects.

Sub Constructor(URL as text, MIMEType as text, expectedContentLength as Integer, textEncodingName as text)

Initialize an NSURLResponse with the provided values.Sub Destructor()

the DestructorFunction copy() As NSURLResponseMB

creates a copy of the objectShared Function localizedStringForStatusCode(statusCode as Integer) As text

Convenience method which returns a localized stringcorresponding to the status code for this response.the status code to use to produce a localized string.returns a localized string corresponding to the given status code.

Note "About"An NSURLResponse object represents a URL load response in amanner independent of protocol and URL scheme.

NSURLResponse encapsulates the metadata associatedwith a URL load. Note that NSURLResponse objects do not containthe actual bytes representing the content of a URL. SeeNSURLConnection and NSURLConnectionDelegate for more informationabout receiving the content data for a URL load.

An NSHTTPURLResponse object represents a response to anHTTP URL load. It is a specialization of NSURLResponse whichprovides conveniences for accessing information specific to HTTPprotocol responses.

Network Kit Manual, Page � of �18 26

Page 19: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

Property Handle As IntegerEnd Class

Network Kit Manual, Page � of �19 26

Page 20: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSURLConnectionMemoryMB

Class NSURLConnectionMemoryMB Inherits NSURLConnectionMBSub Constructor(Handle as Integer)

creates connection with given handleSub Constructor(request as NSURLRequestMB)

creates connection with given requestSub Constructor(request as NSURLRequestMB, startImmediately as Boolean)

creates connection with given request and optionally starts it directlyNote "About"

This is the NSURLConnectionMB subclass to handle memory based downloads

-> download to MemoryBlock-> download and write yourself to socket, binarystream, serialport or whatever

use NSURLConnectionFileMB to download to file directlyProperty CollectData As Boolean

// whether to collect data for this downloadProperty Data As xojo.Core.MutableMemoryBlock

// the memoryblock where we collect dataEnd Class

Network Kit Manual, Page � of �20 26

Page 21: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

NSURLConnectionFileMB

Class NSURLConnectionFileMB Inherits NSURLConnectionMBSub Constructor(Handle as Integer)

creates connection with given handleSub Constructor(request as NSURLRequestMB)

creates connection with given requestSub Constructor(request as NSURLRequestMB, startImmediately as Boolean)

creates connection with given request and optionally starts it directlyNote "About"

This is the NSURLConnectionMB subclass to handle file based downloads

use NSURLConnectionMemoryMB to download to MemoryBlock or write data yourself to a file or database.

End Class

Network Kit Manual, Page � of �21 26

Page 22: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

Version HistoryTip: If you want to update your existing code with new release, you‘d best compare projects with Arbed (http://www.tempel.org/Arbed) and copy modifications to your project.

1.1, 31st July 2019

• Fixed bugs in documentation.• Updated to Xojo 2019r1• Fixed iOS Table Data Source events

1.0, first release

Known issues• NSConnection file download returns a file URL where we don’t have a file.

Network Kit Manual, Page � of �22 26

Page 23: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

InstallationTo get your projects working with this Network Kit, you need to follow a few steps.

Drop the folder „externals“ into your project and access all the modules and classes. Or copy from existing example projects what you need.

Network Kit Manual, Page � of �23 26

Page 24: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

RequirementsYou need Xojo 2015r1 or newer. We did not test with older versions, but you can if you need.

If you need network functions for Windows, Linux and Mac OS X cross platform, please check our MBS Plugins, especially the Network and CURL plugin parts.

For Linux you can use MBS Linux Plugin with avahi classes.

Network Kit Manual, Page � of �24 26

Page 25: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

LicenseSummary:• You may use Network Kit only with one licensed Xojo installation.• You agree not to share the Network Kit or use someone else's Network Kit copy.

Christian Schmitz Software GmbH, of Nickenich Germany is the owner, developer and sole copyright holder of this product, which is licensed -not sold- to you on a non-exclusive basis.You agree not to share your MBS Xojo Network Kit with anyone.

You may transfer your license to another person only after receiving written authorization from Christian Schmitz Software GmbH and only if the recipient agrees to be bound by the terms of this agreement.Christian Schmitz Software GmbH reserves the right to cancel the license key(s) of any user who Christian Schmitz Software GmbH determines is in violation of this agreement.THE WARRANTIES IN THIS AGREEMENT REPLACE ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE IS PROVIDED "AS IS" AND Christian Schmitz Software GmbH DISCLAIMS AND EXCLUDES ALL OTHER WARRANTIES. IN NO EVENT WILL Christian Schmitz Software GmbH BE LIABLE FOR ANY SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, EVEN IF WE HAVE KNOWLEDGE OF THE POTIENTIAL LOSS OR DAMAGE.If you are located in Germany this agreement is subject to the laws of Germany. If you are located outside Germany local law may apply. Some states do not allow the exclusion of warranties, so the above exclusion may not apply to you.Christian Schmitz Software GmbH does not charge royalties or deployment fees for Xojo applications.

Access to updates is included for one year. After that time you can order an update or keep using the old version you have.

Network Kit Manual, Page � of �25 26

Page 26: MBS Xojo Network Kit - MonkeyBread Software€¦ · use network functions in iOS. The Kit contains: • Wrapper for OS X and iOS Bonjour classes to publish service and browser for

ContactChristian Schmitz Software GmbH Eckertshohl 22 56645 Nickenich Germany

Email: [email protected]

Phone: +49 26 32 95 89 55 (Office) or +49 17 58 36 37 10 (Mobile)

Network Kit Manual, Page � of �26 26


Recommended