最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Is POCO++ capable of port sharing? - Stack Overflow

programmeradmin3浏览0评论

The main goal is to introduce a REST API to an existing service written in C++ and POCO seems to be the best match for that.There are other services that need to run on the same machine.

I already have a very basic implementation that is working BUT only when no other service is running on the same port. Of course all services are supposed to run on port 80 for HTTP and on port 443 for HTTPS. The other services are written in .NET and are either WCF services running on .NET framework 4.7.2 or .NET 8 web services. It's also possible to have an IIS running next to it. They all run on ports 80 and/or 443, no problem. Everything is running on Windows only.

When using POCO in the C++ service, there is always an error. Either the .NET services can't start, or if they already run, POCO has an error. If the C++ service is started first, I get my (yet) static response when accessing 127.0.0.1 (so it works fine) in the browser but starting the other services give me these errors:

  • WCF service: TCP port 80 is being used by another application
  • .NET 8 service: Microsoft.AspNetCore.Server.HttpSys.HttpSysException (32): The process cannot access the file because it is being used by another process.

When one of the other services is running and then starting the C++ service, POCO generates an exception with this error message: Permission denied

Here is the code (please ignore memory management, this is just for a POC)

Poco::Net::SocketAddress addr("0.0.0.0", 80);
Poco::Net::ServerSocket socket(addr);
socket.setReusePort(true);
socket.setReuseAddress(true);
Poco::Net::HTTPServer httpServer(new PocoRequestHandlerFactory("some format"), socket, new Poco::Net::HTTPServerParams());
httpServer.start();

POCO throws the exception in this line: Poco::Net::ServerSocket socket(addr);

I also tried to start like this:

Poco::Net::SocketAddress addr("0.0.0.0", 80);
Poco::Net::ServerSocket socket;
socket.bind(addr, true, true);

but that just causes the exception to be thrown in socket.bind().

Is it actually possible to do port sharing with POCO on Windows? If yes, how does it work?

The main goal is to introduce a REST API to an existing service written in C++ and POCO seems to be the best match for that.There are other services that need to run on the same machine.

I already have a very basic implementation that is working BUT only when no other service is running on the same port. Of course all services are supposed to run on port 80 for HTTP and on port 443 for HTTPS. The other services are written in .NET and are either WCF services running on .NET framework 4.7.2 or .NET 8 web services. It's also possible to have an IIS running next to it. They all run on ports 80 and/or 443, no problem. Everything is running on Windows only.

When using POCO in the C++ service, there is always an error. Either the .NET services can't start, or if they already run, POCO has an error. If the C++ service is started first, I get my (yet) static response when accessing 127.0.0.1 (so it works fine) in the browser but starting the other services give me these errors:

  • WCF service: TCP port 80 is being used by another application
  • .NET 8 service: Microsoft.AspNetCore.Server.HttpSys.HttpSysException (32): The process cannot access the file because it is being used by another process.

When one of the other services is running and then starting the C++ service, POCO generates an exception with this error message: Permission denied

Here is the code (please ignore memory management, this is just for a POC)

Poco::Net::SocketAddress addr("0.0.0.0", 80);
Poco::Net::ServerSocket socket(addr);
socket.setReusePort(true);
socket.setReuseAddress(true);
Poco::Net::HTTPServer httpServer(new PocoRequestHandlerFactory("some format"), socket, new Poco::Net::HTTPServerParams());
httpServer.start();

POCO throws the exception in this line: Poco::Net::ServerSocket socket(addr);

I also tried to start like this:

Poco::Net::SocketAddress addr("0.0.0.0", 80);
Poco::Net::ServerSocket socket;
socket.bind(addr, true, true);

but that just causes the exception to be thrown in socket.bind().

Is it actually possible to do port sharing with POCO on Windows? If yes, how does it work?

Share Improve this question edited Mar 11 at 12:32 MSalters 181k11 gold badges169 silver badges373 bronze badges asked Mar 11 at 8:23 gyungyun 811 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 5

It is wrong to call it "port sharing". What actually happens is that applications register themselves as available servers to a Windows Service called HTTP.sys and that service is in charge of dispatching requests to the correct instance based on the requested IP and path.

Given that the POCO project does not contain a single call to HttpInitialize (the entry point for that registration API) you will have to bridge the gap yourself.

发布评论

评论列表(0)

  1. 暂无评论