CotpServerOpenAsync(Boolean, String, NotifyDataChangedEventHandler, Int32) Method |
Open a COTP server.
Creates a server and starts accepting connections, calling 'dataChangedHandler' with data from each connection as it arrives.
This method returns after the server has been established, leaving the accepting and servicing of connections to a background thread.
Namespace: Demo3D.Net.ProtocolsAssembly: Demo3D.IO (in Demo3D.IO.dll) Version: 19.00.00
Syntaxpublic static Task<ServerSocket> OpenAsync(
bool sync,
string tsap,
NotifyDataChangedEventHandler dataChangedHandler,
int port = -1
)
Parameters
- sync Boolean
- If true, the Task returned is guaranteed to be complete.
- tsap String
- The local TSAP to open the server on.
- dataChangedHandler NotifyDataChangedEventHandler
- Delegate for servicing new data arriving on a client connection.
- port Int32 (Optional)
- ISO port number.
Return Value
TaskServerSocketThe COTP protocol socket.
Example
public async Task StartServerAsync(string tsap) {
await CotpServer.OpenAsync(sync: false, tsap, DataReceived);
}
void DataReceived(ProtocolSocket socket, object service, NotifyDataChangedEventArgs e) {
var io = (IPacketIOService)service;
var args = (PacketChangedEventArgs)e;
var message = args.GetData();
string str = BinaryTextEncoding.FixedLengthASCII.GetString(message);
Logger.Log("Message received: " + message);
var reply = BinaryTextEncoding.NullTerminatedASCII.GetBytes("hello");
io.Write(reply);
}
See Also