Click or drag to resize

ProtocolAddress Constructor (String)

Constructs a new protocol address by parsing the supplied address string.

Namespace:  Demo3D.Net
Assembly:  Demo3D.IO (in Demo3D.IO.dll) Version: 15.0.2.11458
Syntax
C#
public ProtocolAddress(
	string address
)

Parameters

address
Type: SystemString
The address.
Examples
C#
using System;
using System.Collections;
using System.Threading.Tasks;
using Demo3D.IO;
using Demo3D.Native;
using Demo3D.Net;
using Demo3D.Visuals;

namespace Examples.Net.ClientExample {
    [Auto] public class Client {
        [Auto] IBuilder                    app;
        [Auto] PrintDelegate               print;
        [Auto] SimplePropertyValue<string> tcpAddress;  // The hostname to connect to.
        [Auto] SimplePropertyValue<int>    tcpPort;     // The port to connect to.

        [Auto] IEnumerable OnInitialize(Visual sender) {
            yield return Connect();
        }

        async Task Connect() {
            Client<IPacketIOService> tcpClient = null;

            try {
                // Construct the address explicitly.
                var address = new ProtocolAddress("tcp://host:1234");

                // Connect to the server using the configured tcpAddress and tcpPort.
                tcpClient = await Client<IPacketIOService>.OpenAsync(sync: false, address);

                // Start sending messages to the server.
                await SendMessages(tcpClient);
            }
            catch (Exception e) {
                // If there's an error, close the connection and report the error.
                tcpClient?.Close(e);
            }
        }

        async Task SendMessages(Client<IPacketIOService> tcpClient) {
            // Send a message to the server once a second while the model is running.
            for (int msg = 0; app.Running; msg++) {
                // Construct a packet.
                var writer = new BufferWriter();
                writer.WriteInt32LE(msg);  // Fill the packet with our message - a 32bit integer.
                var buffer = writer.Resolve();

                // Send the packet data.
                await tcpClient.IO.WriteAsync(buffer);

                // Wait one second.
                await Task.Delay(1000);
            }
        }
    }
}
See Also