CotpServerOpen(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 ServerSocket Open(
string tsap,
NotifyDataChangedEventHandler dataChangedHandler,
int port = -1
)
Parameters
- 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
ServerSocketThe COTP protocol socket.
Example
public void StartServer(string tsap) {
CotpServer.Open(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