0
votes

I implemented a middleware example regarding the following tutorial: https://radu-matei.com/blog/aspnet-core-websockets-middleware/. I tried to connect via http and websockets and it worked fine.

After that I tried to connect with the tcpclient class to the middleware but was not able to establish a connection.

then I tried it with the tcplistener class like in older .net versions: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.server.kestrel.internal.http.tcplistener?view=aspnetcore-1.1&viewFallbackFrom=aspnetcore-2.1.

I implemented a tcplistener in the main method of the application, which is listening on a different port than the middleware. Therefore I have two servers a websocketserver and a tcpserver in the app.

I want avoid the tcp server, which was created with tcplistener and manage the tcpclient connection with the middleware. Is it possible to accept besides the websocket connection a tcpclient connection in a .net core middleware?

1

1 Answers

0
votes

Behind the scene web socket is a TCP connection but not at first , a http/https request from web socket client will arrive at dotnet core http server(like Krestel) but later upgrade packet will be sent which will upgrade the connection to a TCP connection so in fact you already are working with a TCP connection but you cannot make a connecttion with a TCP client to a web socket server. What you can do is to use a .net web socket client implementation instead which will take care of the initial upgrade part and you will end up having a TCP connection's capabilities.