简体   繁体   中英

C# server-side socket sender?

I'm trying to muddle my way through setting up a server with a socket port, but I can't find any good references/examples for my situation.

Pretty much all server-side examples go:

  • Listen for socket to connect
  • Receive msg from client
  • Reply to client
  • End communications

What I want to do is:

  • Listen for socket to connect
  • Begin sending data intermittently (as data updates arrive)
  • Continue until the connection is broken

I'm considering taking the standard example , simply skipping the receive, then setting up to repeatedly send (based on receiving events inside the server), but I don't have high confidence in that and I'd like to know what the standard approach to this problem is.

Also, if I want to have multiple ports open do I have to manually assign IP ports, or can than be done automagically?

You can find one of the libraries here . There are some samples in demo project and I think CustomWireProtocol is a sample project that can solve your problem. You can change the client code to send continious messages to server.

I'd recommend looking into Nanomsg by the author of ZeroMQ . Here's an example from a .NET binding project on github:

https://github.com/mhowlett/NNanomsg/blob/master/Example/Program.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM