Overview
  Next

The Network library allows two or more computers (desktops or devices) to communicate over a network.
It uses the TCP protocol.
One computer is the server and the other computers are the clients.
The communication is a synchronous communication, which means that the program will block until the request completes.
The Network library includes two objects: Server and Client objects.
The Server object listens for incoming connections. When a client is waiting for a connection, calling Server.Accept will create a connection.
Server.Accept also creates a Client object. The communication is done using the two (or more) Client objects.
The Client object connects to a server using the Connect method.
This method requires the IP and port number of the server.
You can use GetIP method to find the IP of a known host.
When a connection is created, the data I/O operations are done with the Client.GetStream method which creates a new BinaryFile object (stream).
Using the BinaryFile object you read and write to the stream like a file stream.
One difference is that on a network stream each operation will be blocked until it is completed.
For example if you send a byte using BinaryFile.WriteByte this operation will wait until the other side reads this byte using BinaryFile.ReadByte.
Activesync can be used as the network provider. However the device must be the client and the desktop must wait for the connection before the device tries to connect.
The host name of the desktop when using Activesync is PPP_PEER.
Two important properties are available to prevent the program from blocking:
Server.Pending which returns true if a client is waiting for the connection,
and Client.DataAvailable which returns true if there is any data in the stream.

Another, more complex example is available on Basic4ppc site.
Example:
'****** Server side *******
'stream is a BinaryFile object, server is a Server object and client is a Client object.

Sub Globals
      
End Sub

Sub App_Start
      server.New1(50000) 'Listens on port 50000 (all ip's available).
      server.Start
      client.New1
      client.Value = server.Accept 'This line will block waiting for the other client to connect (or timeout).
      msgbox("Server connected.")
      stream.New1(client.GetStream,false) 'Creates a BinaryFile object using the GetStream method.
      stream.WriteString("This message will be sent to the client.")
End Sub


'******Client side*******
'stream is a BinaryFile object and client is a Client object.
'If you are using Activesync to make the connection then the device should be the client and the server code should be running on the desktop before running the client code.
Sub Globals

End Sub

Sub App_Start
      client.New1
      client.Connect(client.GetIP2("PPP_PEER"),50000) 'Use Activesync IP.
      msgbox("Client connected.")
      stream.New1(client.GetStream,false)
      msgbox(stream.ReadString)
      client.Close
End Sub