Press on the image to return to the main documentation page.
The network library includes two objects for working with TCP: Socket, ServerSocket With Socket you can communicate with other devices and computers over TCP/IP. ServerSocket allows you to listen for incoming connections. Once a connection is established you will receive a Socket object that will be used for handling this specific connection. See the Network tutorial. It also includes two objects for working with UDP: UDPSocket and UDPPacket. See UDPSocket for more information.
The ServerSocket object allows other machines to connect to this machine. The ServerSocket listens to a specific port. Once a connection arrives, the NewConnection event is raised with a Socket object. This Socket object should be used to communicate with this client. You may call Listen again and receive more connections. A single ServerSocket can handle many connections. For each connection there should be one Socket object.
NewConnection (Successful As Boolean, NewSocket As Socket)
Closes the ServerSocket. This will not close any other sockets. You should call Initialize if you want to use this object again.
Returns the server's IP. Will return "127.0.0.1" (localhost) if no other IP is found.
Initialize (PortAsInt, EventNameAsString)
Initializes the ServerSocket. Port - The port that the server will listen to. Note that you should call Listen to start listening. Port numbers lower than 1024 are restricted by the system. EventName - The event Sub prefix name.
Tests whether the object is initialized.
Starts listening in the background for incoming connections. When a connection is established, the NewConnection event is raised. If the connection is successful a Socket object will be passed in the event. Calling Listen while the ServerSocket is listening will not do anything.
The Socket object is an endpoint for network communication. If you are connecting to a server then you should initialize a Socket object and call Connect with the server address. The Connected event will be raised when the connection is ready or if the connection has failed. Sockets are also used by the server. Once a new incoming connection is established, the NewConnection event will be raised and an initialized Socket object will be passed as a parameter. Once a socket is connected you should use its InputStream and OutputStream to communicate with the other machine.
Closes the socket and the streams. It is safe to call this method multiple times.
Connect (HostAsString, PortAsInt, TimeOutAsInt)
Tries to connect to the given address. The connection is done in the background. The Connected event will be raised when the connection is ready or if it has failed. Host - The host name or IP. Port - Port number. TimeOut - Connection timeout. Value is specified in milliseconds. Pass 0 to disable the timeout.
Initializes a new SSL socket. EventName - Sets the sub that will handle the Connected event. KeystoreStream - An InputStream that points to an alternate keystore. Pass Null to use the default keystore. Password - Custom keystore password.
InputStreamAsjava.io.InputStream [read only]
Returns the socket's InputStream which is used to read data.
Tests whether the object was initialized.
OutputStreamAsjava.io.OutputStream [read only]
Returns the socket's OutputStream which is used to write data.
RemoteAddressAsString [read only]
Returns the address of the remote endpoint or an empty string if it is not connected.
ResolveHost (HostAsString) AsString
Resolves the host name and returns the IP address.
Gets or sets the timeout of the socket's InputStream. Value is specified in milliseconds. By default there is no timeout.
A packet of data that is being sent or received. To send a packet call one of the Initialize methods and then send the packet by passing it to UDPSocket.Send. When a packet arrives you can get the data in the packet from the available properties.
UDPSocket supports sending and receiving UDPPackets. Sending packets is done by calling the Send method. When a packet arrives the PacketArrived event is raised with the packet. This example sends a string message to some other machine. When a packet arrives it converts it to string and shows it: SubProcess_Globals PrivateMsgboxAsMsgboxes DimUDPSocket1AsUDPSocket EndSub
SubAppStart (Form1AsForm, Args() AsString)
UDPSocket1.Initialize("UDP", 5000, 8000)
DimPacketAsUDPPacket Dimdata() AsByte data = "Hello from RaspBerry".GetBytes("UTF8")
Packet.Initialize(data, "localhost", 5000)
Initializes the socket and starts listening for packets. EventName - The name of the Sub that will handle the events. Port - Local port to listen on. Passing 0 will cause the OS to choose an available port automatically. ReceiveBufferSize - The size of the receiving packet. Packets larger than this value will be truncated. Pass 0 if you do not want to receive any packets.
Similar to Initialize. ReuseAddress - If true then the SO_REUSEADDR flag is set which means that multiple processes can open the port. In that case broadcasted messages will arrive to all processes. LoopbackOnly - If true then the socket will be bound to the local host. It will only receive messages sent by other processes.
Tests whether this object is initialized.
PortAsInt [read only]
Gets the local port that this socket listens to.
Sends a Packet. The packet will be sent in the background (asynchronously).