Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

RAWSocketMBS.Bind(DestAddr as Ptr, DestAddrByteSize as Integer) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Binds the socket to the given destination address.
Notes:
Set ReuseAddress to bind to an address which already a socket is bound to.
Lasterror is set.
Returns true on success and false on failure.
Please specify with port and IP in destAddress where to bind against.
Structure of DestAddress is OS and address family dependent.

See also:

Feedback, Comments & Corrections

RAWSocketMBS.Bind(Port as Integer, IP as string = "")
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Binds the socket to the given port.
Notes:
If IP is not empty, you can bind the socket to only the given network interface with that IPv4.
Set ReuseAddress to bind to an address which already a socket is bound to.
Lasterror is set.

See also:

Feedback, Comments & Corrections

RAWSocketMBS.Connect(DestAddr as Ptr, DestAddrByteSize as Integer) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Connects to destination address.
Notes:
lasterror is set.
Returns true on success and false on failure.
Please specify with port and IP in destAddress where package is sent to.
Structure of DestAddress is OS and address family dependent.

Feedback, Comments & Corrections

RAWSocketMBS.Constructor(AddressFamily as Integer, SocketType as Integer, Protocol as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: The constructor.
Example:
dim sock as RAWSocketMBS

// create UDP socket
sock = new RAWSocketMBS(RAWSocketMBS.AddressFamilyINet, RAWSocketMBS.SocketTypeDatagram, RAWSocketMBS.ProtocolUDP)
Notes:
Please pass valid combination of OS supported sockets.
Raises exception if creation is not possible.
Raw socket requires root access.

Feedback, Comments & Corrections

RAWSocketMBS.Destructor
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: The destructor.
Notes: Closes the socket.

Feedback, Comments & Corrections

RAWSocketMBS.Read(ByteSize as Integer, peek as boolean = false) as MemoryBlock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Read at maximum the given number of bytes in buffer.
Notes:
Pass true for peek if data should not be removed from receiving buffer.
Lasterror is set.

Be aware that you may not get whole packages here, so data may come in several chunks.
For that, please collect the data and look for whether your package is complete or a required end mark arrived.

Feedback, Comments & Corrections

RAWSocketMBS.ReadAll(peek as boolean = false) as MemoryBlock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Read all bytes in buffer.
Example:
dim sock as RAWSocketMBS
dim data as MemoryBlock = sock.ReadAll
if data = nil then
// nothing read
else

end if
Notes:
Pass true for peek if data should not be removed from receiving buffer.
Lasterror is set.

Be aware that you may not get whole packages here, so data may come in several chunks.
For that, please collect the data and look for whether your package is complete or a required end mark arrived.

Feedback, Comments & Corrections

RAWSocketMBS.ReadDatagram(peek as boolean = false) as DatagramMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Reads a datagram.
Notes:
If peek is true, the data is not removed from read buffer.
On error returns nil.

Feedback, Comments & Corrections

RAWSocketMBS.Send(Data as Ptr, DataByteSize as Integer, Flags as Integer = 0) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Sends data.
Notes:
Data is sent to address passed with Connect method.
Returns number of bytes sent.
Lasterror is set.

Feedback, Comments & Corrections

RAWSocketMBS.SendMessage(Data as DatagramMBS) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Sends a datagram.
Notes:
Please specify with port and address of datagram where package is sent to.
Returns number of bytes sent.
Lasterror is set.

See also:

Feedback, Comments & Corrections

RAWSocketMBS.SendMessage(Data as MemoryBlock, IP as String, Port as Integer) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Sends a datagram.
Notes:
Please specify with port and IP where package is sent to.
Returns number of bytes sent.
Lasterror is set.

See also:

Feedback, Comments & Corrections

RAWSocketMBS.SendMessage(Data as string, IP as String, Port as Integer) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Sends data to target.
Notes:
Please specify with port and IP where package is sent to.
Returns number of bytes sent.
Lasterror is set.

See also:

Feedback, Comments & Corrections

RAWSocketMBS.SendTo(Data as Ptr, DataByteSize as Integer, Flags as Integer, DestAddr as Ptr, DestAddrByteSize as Integer) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Network MBS Network Plugin 17.4 Yes Yes Yes Yes No
Function: Sends data to dest address.
Example:
dim sock as RawSocketMBS
dim Flags as integer
dim r as Integer

// port
dim port as integer = val(iPort.Text)
if port <= 0 or port >= 65535 then
break
MsgBox "Wrong port: "+iPort.Text
Return
end if

// dest address

'/*
'* Socket address, internet style. C declaration for Mac
'*/
'struct sockaddr_in {
'__uint8_t sin_len; // 1 byte, Mac only
'sa_family_t sin_family; // 1 byte
'in_port_t sin_port; // 2 byte in Network byte order
'struct in_addr sin_addr; // 4 byte
'char sin_zero[8]; // 8 bytes filler

'};

// convert IPv4 from text to numeric value
dim IP as Uint32 = RAWSocketMBS.inet_addr(iIP.Text)

// create destination address. This is for Mac! Windows and Linux have different structures
dim dest as new MemoryBlock(16)
dest.UInt8Value(0) = dest.size
dest.UInt8Value(1) = RAWSocketMBS.AddressFamilyINet
dest.UInt16Value(2) = RAWSocketMBS.htons(port)
dest.UInt32Value(4) = IP

// message
dim m as string = ConvertEncoding(iMessage.Text, encodings.UTF8)
dim data as MemoryBlock = m

// send
r = sock.SendTo(data, data.size, Flags, dest, dest.size)
Notes:
Please specify with port and IP in destAddress where package is sent to.
Returns number of bytes sent. Structure of DestAddress is OS and address family dependent.
Lasterror is set.

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Network Plugin.




Links
MBS Xojo blog