# Getting started

> Tutorial: Set up your first server with the OPC UA .NET SDK: import the namespace, create the server, start it, and stop it again.

> This content was machine translated and may contain errors. [Read in German](https://www.traeger.de/docs/development/opcua/server/getting-started)

**Sample applications:**

- Server.Temperature ([C#](https://github.com/Traeger-GmbH/opcuanet-samples/tree/master/cs/Scenarios/Server.Temperature), [VB.NET](https://github.com/Traeger-GmbH/opcuanet-samples/tree/master/vb/Scenarios/Server.Temperature)): This sample demonstrates how to setup an OPC UA server that provides a temperature node and updates its value once per second.
- Client.Temperature ([C#](https://github.com/Traeger-GmbH/opcuanet-samples/tree/master/cs/Scenarios/Client.Temperature), [VB.NET](https://github.com/Traeger-GmbH/opcuanet-samples/tree/master/vb/Scenarios/Client.Temperature)): This sample demonstrates how to connect to an OPC UA server and read the value of a node once per second.

## Prerequisites

- **Target framework:** .NET or .NET Framework 4.7.2 or later, all supported frameworks under [Target frameworks](https://www.traeger.de/en/docs/development/opcua/requirements#target-frameworks)
- **NuGet package:** `Opc.UaFx.Advanced` ([Downloads](https://www.traeger.de/en/docs/development/opcua/downloads))
- **License:** not required for the evaluation. Without a license key, the SDK runs with its full feature set, limited to 30 minutes per application launch ([Set up the license](https://www.traeger.de/en/docs/development/opcua/license-setup#evaluation))

## Create the server

**1.** Add a reference to the `Opc.UaFx.Server` namespace (package `Opc.UaFx.Advanced`). Most other types are in the `Opc.UaFx` namespace:

```csharp
using Opc.UaFx.Server;
```

```vbnet
Imports Opc.UaFx.Server
```

**2.** Create an instance of the `OpcServer` class with the default base address you want. If you omit it, the server uses the address `opc.tcp://localhost:4840`:

```csharp
var server = new OpcServer("opc.tcp://localhost:4840/");
```

```vbnet
Dim server = New OpcServer("opc.tcp://localhost:4840/")
```

## Start the server

**3.** Start the server and serve clients:

```csharp
server.Start();
```

```vbnet
server.Start()
```

**4.** Your code that handles the client requests:

```csharp
// Your code to process client requests.
```

```vbnet
'Your code to process client requests.
```

## Stop the server

**5.** Before the application exits, close all sessions and shut down the server:

```csharp
server.Stop();
```

```vbnet
server.Stop()
```

## Server in a using block

**6.** With a `using` block, it looks like this:

```csharp
using (var server = new OpcServer("opc.tcp://localhost:4840/")) {
    server.Start();
    // Your code to process client requests.
}
```

```vbnet
Using server As new OpcServer("opc.tcp://localhost:4840/")
    server.Start()
    'Your code to process client requests.
End Using
```

## Server in tests

You can start a server with test nodes in the same process as a client to test client logic automatically without a plant. The [Test clients](https://www.traeger.de/en/docs/development/opcua/client/testing) page shows how.

## Complete example

Your own server that provides a temperature node, updates its value
cyclically, and serves the subscriptions of clients:

```csharp
namespace Server
{
    using System.Threading;

    using Opc.UaFx;
    using Opc.UaFx.Server;

    /// <summary>
    /// This sample demonstrates how to setup an OPC UA server that provides a temperature node and
    /// updates its value once per second.
    /// </summary>
    public class Program
    {
        public static void Main()
        {
            var temperatureNode = new OpcDataVariableNode<double>("Temperature", 100.0);

            using (var server = new OpcServer("opc.tcp://localhost:4840/", temperatureNode)) {
                server.Start();

                while (true) {
                    if (temperatureNode.Value == 110)
                        temperatureNode.Value = 100;
                    else
                        temperatureNode.Value++;

                    temperatureNode.ApplyChanges(server.SystemContext);
                    Thread.Sleep(1000);
                }
            }
        }
    }
}

```

```vbnet
Imports System.Threading

Imports Opc.UaFx
Imports Opc.UaFx.Server

Namespace Server
    ''' <summary>
    ''' This sample demonstrates how to setup an OPC UA server that provides a temperature node and
    ''' updates its value once per second.
    ''' </summary>
    Public Class Program
        Public Shared Sub Main()
            Dim temperatureNode = New OpcDataVariableNode(Of Double)("Temperature", 100.0)

            Using server = New OpcServer("opc.tcp://localhost:4840/", temperatureNode)
                server.Start()

                While True
                    If (temperatureNode.Value = 110) Then
                        temperatureNode.Value = 100
                    Else
                        temperatureNode.Value += 1
                    End If

                    temperatureNode.ApplyChanges(server.SystemContext)
                    Thread.Sleep(1000)
                End While
            End Using
        End Sub
    End Class
End Namespace

```

The server provides the `Temperature` node and raises its value once per second from 100 to 110, then starts again at 100. To check it, use the client from the [complete example](https://www.traeger.de/en/docs/development/opcua/client/getting-started#complete-example) of client development: it reads the value once per second and prints it.

## Next steps

- [Manage nodes](https://www.traeger.de/en/docs/development/opcua/server/node-management): Create nodes in the address space of the server, control their visibility, and update them at runtime.

- [Read and write values](https://www.traeger.de/en/docs/development/opcua/server/read-write-values): Provide the values of nodes in the server and handle read and write access from clients.

- [Node models](https://www.traeger.de/en/docs/development/opcua/server/node-models): Use OpcNodeModel to define which child nodes are created with a typed node, and take initial values from the type definition.

- [Secure servers](https://www.traeger.de/en/docs/development/opcua/security/server): Secure the server: endpoints, certificates, users, roles and access control lists, audit events, and a checklist for production.
