Git Product home page Git Product logo

simpleudp's Introduction

alt tag

SimpleUdp

Simple wrapper for UDP client and server in C#

NuGet Version NuGet

SimpleUdp provides simple methods for creating your own UDP-based sockets application, enabling easy integration of sending data, receiving data, and building state machines.

New in v2.0.x

  • Retarget to .NET 8.0
  • Removal of Start, Stop APIs, and, the started event
  • Better multi-platform compatibility (Windows, Mac OSX, Ubuntu)

Help or Feedback

Need help or have feedback? Please file an issue here!

Special Thanks

Thanks to community members that have helped improve this library! @jholzer @charleypeng @seatrix

Need TCP Instead?

I have you covered.

Don't know what to use? Just ask! File an issue, I'll be happy to help.

Simple Example

Start a node.

using SimpleUdp;

UdpEndpoint udp = new UdpEndpoint("127.0.0.1", 8000);
udp.EndpointDetected += EndpointDetected;

// only if you want to receive messages...
udp.DatagramReceived += DatagramReceived;

// send a message...
udp.Send("127.0.0.1", 8001, "Hello to my friend listening on port 8001!");

static void EndpointDetected(object sender, EndpointMetadata md)
{
  Console.WriteLine("Endpoint detected: " + md.Ip + ":" + md.Port);
}

static void DatagramReceived(object sender, Datagram dg)
{
  Console.WriteLine("[" + dg.Ip + ":" + dg.Port + "]: " + Encoding.UTF8.GetString(dg.Data));
} 

The Node Project

Start node 1.

Node\bin\Debug\netcoreapp3.1> node 127.0.0.1 8000

Start node 2.

Node\bin\Debug\netcoreapp3.1> node 127.0.0.1 8001

Send message from node 1 to node 2. To do this, enter a command as follows:

[ip:port] [msg]

i.e.

127.0.0.1:8001 hello to my friend running on port 8001!
[127.0.0.1:8000 Command/? for help]: 127.0.0.1:8001 hello to my friend on port 8001!

Send message from node 2 to node 1.

[127.0.0.1:8001 Command/? for help]: Endpoint detected: 127.0.0.1:8000
[127.0.0.1:8000]: hello to my friend on port 8001!
127.0.0.1:8000 hello back to you my friend!

Version History

Please refer to CHANGELOG.md.

simpleudp's People

Contributors

charleypeng avatar jchristn avatar seatrix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

simpleudp's Issues

Unhandled exception. System.Net.Sockets.SocketException (98): Address already in use

Unhandled exception. System.Net.Sockets.SocketException (98): Address already in use
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at System.Net.Sockets.UdpClient..ctor(Int32 port, AddressFamily family)
at System.Net.Sockets.UdpClient..ctor(Int32 port)
at SimpleUdp.UdpEndpoint..ctor(String ip, Int32 port)
at pidemo.Program.Main(String[] args) in E:\Projects\netcoreapi\pidemo\pidemo\Program.cs:line 102
It doesn't seem to work in the arm environment!

"Could not load file or assembly"

Dear,

When running this:

l_udp = new UdpEndpoint(Computer.ThisComputer_IP(), l_DevicePort.IpPort);

where =172.30.0.150 and the device port is 4446, so pretty straightforward Ip and port

We get the error:

Could not load file or assembly 'Caching, Version=1.3.4.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

However, we can't seem to find where exactly in the code the file error comes from.

Looking forward to your reply!

Time To Live (TTL)

Does this library support setting the TTL on each packet?

Kind Regards

UDP send on Android phone

Hello Joel,
sorry bothering but I need an idea.
I use SimpleUdp to comm from Android phone into my home network. The app is written with VS-xamarin-.net-core. At least the tests with the android simulator succeed, I receive the UDP telegram on my windows host. But with a installed APK on my phone nothing comes through. The google playstore app "udp sender/receiver" on the phone works well, and if I have open my app too, the port seems to be in use by my app because the playstore app cannot send any more.
Strange! Do you have any idea what might be wrong ...
Greetings from Germany
Uwe

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.