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.
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. This method will return the wifi network IP if it is available.
Returns the IP address of the wifi network. Returns "127.0.0.1" (localhost) if not connected.
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. The keystore format should be BKS. Password - Custom keystore password.
Initializes a new SSL socket that accepts all certificates automatically. This method is less secure as the server certificate is not tested.
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.
ResolveHost (HostAsString) AsString
Resolves the host name and returns the IP address. This method is deprecated and will not work properly on Android 4+ devices.
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 DimUDPSocket1AsUDPSocket EndSub
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.
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).