C ++中的远程过程调用(RPC):当端点被硬编码时,多个客户端可以监听一个服务器吗?(Remote Procedure Call (RPC) in C++: Can multiple Clients listen to one server when endpoint is hard coded?)
我正在编写一个使用
MIDL
和RPC
的简单服务器客户端来允许文件传输。 当端点硬编码如下时,它可以工作:服务器端
status = RpcServerUseProtseqEp( reinterpret_cast<unsigned char*>("ncacn_ip_tcp"), RPC_C_PROTSEQ_MAX_REQS_DEFAULT, reinterpret_cast<unsigned char*>("8888"), NULL);
客户端
status = RpcStringBindingCompose(NULL, "ncacn_ip_tcp", (RPC_CSTR)"127.0.0.1", "8888", NULL, NULL);
我想知道当端点是硬编码时,多个客户端是否能够连接到一台服务器? 我们知道在使用TCP协议的套接字编程中,两个应用程序不能同时连接到单个端口。 但是,
MSDN
参考说RPC
服务器进程使用先进先出的调用队列来处理请求。如果它无法接收来自客户端的多个请求,是否有办法设置端点池? 谢谢。
I'm writing a simple server-client using
MIDL
andRPC
to allow file transferring. It works when endpoint is hard coded as follow:server side
status = RpcServerUseProtseqEp( reinterpret_cast<unsigned char*>("ncacn_ip_tcp"), RPC_C_PROTSEQ_MAX_REQS_DEFAULT, reinterpret_cast<unsigned char*>("8888"), NULL);
Client Side
status = RpcStringBindingCompose(NULL, "ncacn_ip_tcp", (RPC_CSTR)"127.0.0.1", "8888", NULL, NULL);
I'm wondering if multiple clients are able to connect to one server when endpoint is hard coded? As we know that in socket programming using TCP protocol, two application cannot connect to a single port at one time. However, the
MSDN
reference says thatRPC
server process uses a first-in, first-out call queue to handle requests.If it is unable to receive multiple requests from clients, is there a way to set an endpoint pool? Thank you.
原文:https://stackoverflow.com/questions/45941166
最满意答案
您可以使用template属性简化指令
app.directive('daysDirective', function () { return { require: 'ngModel', link: function(scope, element, attr, ngModelController) { //not required, unless you are actually going to use ngModelController }, replace: true, restrict: 'EA', template: ' <div class="input-group">' + ' <button ng-repeat="(key, day) in days track by $index" ng-class="{\'btn btn-sm btn-white\': day.selected, \'btn btn-sm btn-grey\': !day.selected}">{{ day.display }}</button>' + ' </div>', scope: { model: '=ngModel' }, controller: ['$scope', function ($scope) { //this needs to move into your controller, because otherwise all instances will share the same instance of days, causing them to interfere with each other $scope.days = { sun: { display: "S"}, mon: { display: "M"}, tue: { display: "T"}, wed: {display: "W"}, thurs: { display: "T"}, fri: { display: "F"}, sat: { display: "S"} }; $scope.$watchCollection('model', function(){ //clear the selected attribute for(var i in $scope.days) { $scope.days[i].selected = false; } for(var i in $scope.model) { $scope.days[$scope.model[i]].selected = true; } }); }] }; });
您可以完全避免手表的复杂性:
app.directive('daysDirective', function () { var days = { sun: { display: "S"}, mon: { display: "M"}, tue: { display: "T"}, wed: {display: "W"}, thurs: { display: "T"}, fri: { display: "F"}, sat: { display: "S"} }; return { require: 'ngModel', link: function(scope, element, attr, ngModelController) { //not required, unless you are actually going to use ngModelController }, replace: true, restrict: 'EA', template: ' <div class="input-group">' + ' <button ng-click="Toggle(day)" ng-repeat="day in days track by $index" ng-class="{\'btn btn-sm btn-white\': isSelected(day.key), \'btn btn-sm btn-grey\': !isSelected(day.key)}">{{ day.display }}</button>' + ' </div>', scope: { model: '=ngModel' }, controller: ['$scope', function ($scope) { $scope.days = days; $scope.isSelected = function(day) { return $scope.model.indexOf(day) > -1 } $scope.Toggle = function(day) { var idx = $scope.model.indexOf(day.key); if(idx > -1) $scope.model.splice(idx, 1); } else { $scope.model.push(day.key); } } }] }; });
You can simplify your directive by using the template property
app.directive('daysDirective', function () { return { require: 'ngModel', link: function(scope, element, attr, ngModelController) { //not required, unless you are actually going to use ngModelController }, replace: true, restrict: 'EA', template: ' <div class="input-group">' + ' <button ng-repeat="(key, day) in days track by $index" ng-class="{\'btn btn-sm btn-white\': day.selected, \'btn btn-sm btn-grey\': !day.selected}">{{ day.display }}</button>' + ' </div>', scope: { model: '=ngModel' }, controller: ['$scope', function ($scope) { //this needs to move into your controller, because otherwise all instances will share the same instance of days, causing them to interfere with each other $scope.days = { sun: { display: "S"}, mon: { display: "M"}, tue: { display: "T"}, wed: {display: "W"}, thurs: { display: "T"}, fri: { display: "F"}, sat: { display: "S"} }; $scope.$watchCollection('model', function(){ //clear the selected attribute for(var i in $scope.days) { $scope.days[i].selected = false; } for(var i in $scope.model) { $scope.days[$scope.model[i]].selected = true; } }); }] }; });
You can avoid the complexity of the watch altogether:
app.directive('daysDirective', function () { var days = { sun: { display: "S"}, mon: { display: "M"}, tue: { display: "T"}, wed: {display: "W"}, thurs: { display: "T"}, fri: { display: "F"}, sat: { display: "S"} }; return { require: 'ngModel', link: function(scope, element, attr, ngModelController) { //not required, unless you are actually going to use ngModelController }, replace: true, restrict: 'EA', template: ' <div class="input-group">' + ' <button ng-click="Toggle(day)" ng-repeat="day in days track by $index" ng-class="{\'btn btn-sm btn-white\': isSelected(day.key), \'btn btn-sm btn-grey\': !isSelected(day.key)}">{{ day.display }}</button>' + ' </div>', scope: { model: '=ngModel' }, controller: ['$scope', function ($scope) { $scope.days = days; $scope.isSelected = function(day) { return $scope.model.indexOf(day) > -1 } $scope.Toggle = function(day) { var idx = $scope.model.indexOf(day.key); if(idx > -1) $scope.model.splice(idx, 1); } else { $scope.model.push(day.key); } } }] }; });
相关问答
更多-
从ng-disabled指令中删除插值{{ }} :
自定义指令突出显示按(custom directive highlight button)[2023-08-28]
您可以使用template属性简化指令 app.directive('daysDirective', function () { return { require: 'ngModel', link: function(scope, element, attr, ngModelController) { //not required, unless you are actually going to use ngModelController ...如何创建自定义指令来显示ngFileUpload验证消息?(how to create custom directive to show ngFileUpload validation messages?)[2022-04-21]
简单您正在使用elem:'@',这只能用于字符串。 通过看到elem =“nationalCardForm.nationalCard”看起来elem是一个对象,你可以用elem:“=”来试试它。 All of that was my fault, i resolve the problem by these changes: function imageMessages() { var directive = { restrict: 'E', scope: { ...只是替换 scope: { toggleButton: '=checked' } 至 scope: { checked: '=toggleButton' } just replace scope: { toggleButton: '=checked' } to scope: { checked: '=toggleButton' }plnkr的第7版是我最初发布的。 基本上,只要更改了值,就在$ scope.selected上调用$ apply不足以通知另一个指令。 我还必须设置$ watch: $scope.$watch('selected', function(newVal, oldVal) { select2.val(newVal).select2(options); }); 我现在完全不清楚为什么当我在主页面上修改select2指令时,模态中的select2指令在没有$ watch的情况下完全更新。 如果有人能解释那 ...您的example指令是否反映了您将实际指令应用于button元素的方式? 我注意到你的示例指令并没有遵循正确的命名约定,即在指令名称中使用带连字符的小写字母作为每个大写字母。 即myCustomDirective应该应用于按钮,如下所示: 否则,您的指令将不会被编译或链接到该按钮。 除了看到实际的代码,我能想到的唯一的其他事情就是指令的优先级。 ...据我所知,你使用得对(如果指示是正确的) 我认为你以错误的顺序使用了ionNavView和ionView 来自文档Hello!