Click or drag to resize

CotpServer Class

A COTP server.
Inheritance Hierarchy
SystemObject
  Demo3D.Net.ProtocolsCotpServer

Namespace:  Demo3D.Net.Protocols
Assembly:  Demo3D.IO (in Demo3D.IO.dll) Version: 15.0.2.11458
Syntax
C#
public static class CotpServer
Methods
  NameDescription
Public methodStatic memberCode exampleOpen(Byte, NotifyDataChangedEventHandler, Int32)
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.
Public methodStatic memberCode exampleOpen(Byte, ServiceClientAsyncIPacketIOService, Int32)
Open a COTP server. Creates a server and starts accepting connections, calling 'serviceConnection' with each connection established. This method returns after the server has been established, leaving the accepting and servicing of connections to a background thread.
Public methodStatic memberCode exampleOpen(String, NotifyDataChangedEventHandler, Int32)
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.
Public methodStatic memberCode exampleOpen(String, ServiceClientAsyncIPacketIOService, Int32)
Open a COTP server. Creates a server and starts accepting connections, calling 'serviceConnection' with each connection established. This method returns after the server has been established, leaving the accepting and servicing of connections to a background thread.
Public methodStatic memberCode exampleOpenAsync(Byte, NotifyDataChangedEventHandler, Int32)
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.
Public methodStatic memberCode exampleOpenAsync(Byte, ServiceClientAsyncIPacketIOService, Int32)
Open a COTP server. Creates a server and starts accepting connections, calling 'serviceConnection' with each connection established. This method returns after the server has been established, leaving the accepting and servicing of connections to a background thread.
Public methodStatic memberCode exampleOpenAsync(String, NotifyDataChangedEventHandler, Int32)
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.
Public methodStatic memberCode exampleOpenAsync(String, ServiceClientAsyncIPacketIOService, Int32)
Open a COTP server. Creates a server and starts accepting connections, calling 'serviceConnection' with each connection established. This method returns after the server has been established, leaving the accepting and servicing of connections to a background thread.
Public methodStatic memberCode exampleOpenAsync(Boolean, Byte, NotifyDataChangedEventHandler, Int32)
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.
Public methodStatic memberCode exampleOpenAsync(Boolean, Byte, ServiceClientAsyncIPacketIOService, Int32)
Open a COTP server. Creates a server and starts accepting connections, calling 'serviceConnection' with each connection established. This method returns after the server has been established, leaving the accepting and servicing of connections to a background thread.
Public methodStatic memberCode exampleOpenAsync(Boolean, String, NotifyDataChangedEventHandler, Int32)
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.
Public methodStatic memberCode exampleOpenAsync(Boolean, String, ServiceClientAsyncIPacketIOService, Int32)
Open a COTP server. Creates a server and starts accepting connections, calling 'serviceConnection' with each connection established. This method returns after the server has been established, leaving the accepting and servicing of connections to a background thread.
Top
Remarks
This class is a wrapper around ProtocolServer.Open{IPacketIOService} and ProtocolAddressBuilder. See ProtocolServer and ProtocolAddressBuilder for more advanced usage.
Examples

The following example shows a simple ISO COTP server that accepts connections, waits for data to be received and then calls a method to handle the messages read from the each of the clients.

See CotpClient for the implementation of the client that works with this server.

C#
using System;
using Demo3D.Native;
using Demo3D.Net;
using Demo3D.Net.Protocols;
using Demo3D.Visuals;

using Buffer = Demo3D.IO.Buffer;

namespace Examples.Net.CotpServerExample {
    [Auto] public class Server {
        [Auto] IBuilder                    app;
        [Auto] Document                    doc;
        [Auto] PrintDelegate               print;
        [Auto] SimplePropertyValue<string> cotpTsap;     // The tsap to run the server on.

        [Auto] void OnInitialize(Visual sender) {
            // Open a server on the configured cotpTsap.
            // This variant of CotpServer.Open will open the server, accept incoming connections and
            // wait for data to arrive on each of the connections.  It will then call ReceiveMessage
            // when data is received on any of the clients.
            CotpServer.Open(cotpTsap, ReceiveMessage);
        }

        void ReceiveMessage(ProtocolSocket socket, object service, NotifyDataChangedEventArgs e) {
            try {
                var args    = (PacketChangedEventArgs)e;  // A COTP server uses PacketChangedEventArgs.
                var message = args.GetData();             // Read from the packet.

                // Handle the message.
                HandleMessage(message);
            }
            catch (Exception x) {
                socket.Close(x);
            }
        }

        void HandleMessage(Buffer message) {
            print("Message received: " + message.Length + " bytes");
        }
    }
}
See Also