C# (Visual Studio)
How to use NEP in C#?
Option 1: NuGet Package Manager Console
Open the NuGet Package Manager Console: Tools -> NuGet Package Manager -> Package Manager Console and write the following command:
NuGet\Install-Package Nep
NuGet\Install-Package Newtonsoft.Json
NuGet\Install-Package NetMQOption 2: NuGet Package Manager for Solution Interface
Open the NuGet Package Manager for Solution Interface: Tools -> NuGet Package Manager -> Manage NuGet Package for Solution and browse Nep. Select the projects where the NEP library for C# will be installed and select the install button. In the same way, install the Newtonsoft.Json and NetMQ packages
Test a basic Publisher
using Nep;
namespace NepTest
{
// Message to send, used for serialization in JSON
class Msg
{
public int message { get; set; }
}
class Program
{
static void Main(string[] args)
{
// Create a new nep node
// The parameter given to this function must be different for each script
NepNode node = new NepNode("basic_pub_cs");
// Create a new publisher with the topic "test"
NepPublisher pub = node.NewPub("test", "json");
// Define the message to send
Msg msg = new Msg();
int i = 0;
while (i < 50)
{
i++;
// Fill message to send
msg.message = i;
// Send the message with the next line
pub.Publish(msg);
// Use the next line to send messages each 0.5 seconds approx.
System.Threading.Thread.Sleep(500);
}
// Close sockets
pub.Dispose();
node.Close();
Console.WriteLine("Publisher program finished!");
}
}
}Test a basic Subscriber
Last updated