Windows WebSocket Services Listening on Port 8080

I am new to developing Windows services, and I need to build it in C #, which will listen 8080on the data input port , and then analyze it. I found information about System.Net.WebSockets, System.Net.Socketsand third-party libraries such as SuperSocket. Here is an example , but not sure what is going on OnStart()and what goes into the methods of OnStop()my Windows service class. Another example is here , but this also does not apply to the Windows service. For basic Windows service development, here is an MSDN article .

I think this happens in OnStart():

Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
serverSocket.Bind(new IPEndPoint(IPAddress.Any, 8080));
serverSocket.Listen(128);
serverSocket.BeginAccept(null, 0, OnAccept, null);

What would I introduce to OnStop()?

The incoming data stream does not require any authentication. Should I still do the handshake?

Your help is appreciated.

+4
source share
1 answer

Since you want to use port 8080 as a listening port, I'm going to assume that you are mainly dealing with http traffic. Instead of using raw sockets, you should look into the OWIN Self Hosted web server . Alternatively, NancyFx may work.

OnStop() , Windows . . OnStart() . TopShelf, Windows.

+2

Source: https://habr.com/ru/post/1659421/


All Articles