ClientTOpenAsync(Boolean, ProtocolAddress, Flags, Object) Method |
Opens a client connection.
Namespace: Demo3D.NetAssembly: Demo3D.IO (in Demo3D.IO.dll) Version: 19.00.00
Syntaxpublic static Task<Client<T>> OpenAsync(
bool sync,
ProtocolAddress address,
Flags flags = default,
Object? userState = null
)
Parameters
- sync Boolean
- If true, the Task returned is guaranteed to be complete.
- address ProtocolAddress
- Address to connect to.
- flags Flags (Optional)
- Connection flags.
- userState Object (Optional)
- User state.
Return Value
TaskClientTThe new client.
Exampleusing 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;
[Auto] SimplePropertyValue<int> tcpPort;
[Auto] IEnumerable OnInitialize(Visual sender) {
yield return Connect();
}
async Task Connect() {
Client<IPacketIOService> tcpClient = null;
try {
var address = new ProtocolAddress("tcp://host:1234");
tcpClient = await Client<IPacketIOService>.OpenAsync(sync: false, address);
await SendMessages(tcpClient);
}
catch (Exception e) {
tcpClient?.Close(e);
}
}
async Task SendMessages(Client<IPacketIOService> tcpClient) {
for (int msg = 0; app.Running; msg++) {
var writer = new BufferWriter();
writer.WriteInt32LE(msg);
var buffer = writer.Resolve();
await tcpClient.IO.WriteAsync(buffer);
await Task.Delay(1000);
}
}
}
}
See Also