首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从gRPC连接到C++ grpc服务器的错误:连接字符串不匹配:预期的'R‘(82)在字节1处得到'O’(79)

从gRPC连接到C++ grpc服务器的错误:连接字符串不匹配:预期的'R‘(82)在字节1处得到'O’(79)
EN

Stack Overflow用户
提问于 2019-10-22 14:38:04
回答 1查看 485关注 0票数 1

我使用官方示例C++ gRPC创建了一个这里服务器。

我正在尝试使用.NET核心3.0中的grpc-dotnet库来使用这个服务器。我正在使用grpc++在v1.24.x (3e4007e)分支机构。

但是,在连接时,服务器上会出现以下错误:

代码语言:javascript
复制
I1022 10:28:38.903132223   24226 timer_generic.cc:738]       TIMER CHECK END: r=1; next=15010
I1022 10:28:38.903143514   24226 timer_manager.cc:188]       sleep for a 1001 milliseconds
I1022 10:28:39.704884424   24227 tcp_server_posix.cc:242]    SERVER_CONNECT: incoming connection: ipv4:127.0.0.1:35425
D1022 10:28:39.704922757   24227 tcp_posix.cc:1253]          cannot set inq fd=11 errno=92
I1022 10:28:39.704957089   24227 timer_generic.cc:365]       TIMER 0x7ffa640017a8: SET 134812 now 14812 call 0x7ffa640017d8[0x7ffa78ab7210]
I1022 10:28:39.704970089   24227 timer_generic.cc:401]         .. add to shard 9 with queue_deadline_cap=15009 => is_first_timer=false
I1022 10:28:39.704983130   24227 handshaker.cc:131]          handshake_manager 0x7ffa640016f0: error="No Error" shutdown=0 index=0, args={endpoint=0x7ffa640011b0, args=0x7ffa640019b0 {size=2: grpc.primary_user_agent=grpc-c++/1.24.2, grpc.compression_enabled_algorithms_bitset=15}, read_buffer=0x7ffa64001a10 (length=0), exit_early=0}
I1022 10:28:39.705019588   24227 handshaker.cc:164]          handshake_manager 0x7ffa640016f0: handshaking complete -- scheduling on_handshake_done with error="No Error"
I1022 10:28:39.705031005   24227 timer_generic.cc:467]       TIMER 0x7ffa640017a8: CANCEL pending=true
I1022 10:28:39.705065212   24227 timer_generic.cc:365]       TIMER 0x7ffa64003648: SET 7214812 now 14812 call 0x7ffa640035a8[0x7ffa78aff900]
I1022 10:28:39.705076629   24227 timer_generic.cc:401]         .. add to shard 7 with queue_deadline_cap=15009 => is_first_timer=false
I1022 10:28:39.705088003   24227 bdp_estimator.h:53]         bdp[ipv4:127.0.0.1:35425]:sched acc=0 est=65536
I1022 10:28:39.705113295   24227 chttp2_transport.cc:839]    W:0x7ffa64001f00 SERVER [ipv4:127.0.0.1:35425] state IDLE -> WRITING [TRANSPORT_FLOW_CONTROL]
I1022 10:28:39.705126336   24227 chttp2_transport.cc:839]    W:0x7ffa64001f00 SERVER [ipv4:127.0.0.1:35425] state WRITING -> WRITING+MORE [INITIAL_WRITE]
I1022 10:28:39.705137711   24227 init.cc:164]                grpc_init(void)
I1022 10:28:39.705183127   24227 chttp2_transport.cc:1900]   perform_transport_op[t=0x7ffa64001f00]: ON_CONNECTIVITY_STATE_CHANGE:p=0x7ffa640042e0:from=IDLE SET_ACCEPT_STREAM:0x7ffa78aeeaa0(0x7ffa64004278,...)
I1022 10:28:39.705194418   24227 timer_generic.cc:365]       TIMER 0x7ffa640018a8: SET 134812 now 14812 call 0x7ffa640018d8[0x7ffa78b6b670]
I1022 10:28:39.705229459   24227 timer_generic.cc:401]         .. add to shard 6 with queue_deadline_cap=15009 => is_first_timer=false
I1022 10:28:39.705265667   24227 connectivity_state.cc:100]  CONWATCH: 0x7ffa640021a8 server_transport: from IDLE [cur=READY] notify=0x7ffa640042e0
I1022 10:28:39.705322666   24227 chttp2_transport.cc:1900]   perform_transport_op[t=0x7ffa64001f00]: ON_CONNECTIVITY_STATE_CHANGE:p=0x7ffa640042e0:from=READY
I1022 10:28:39.705334041   24227 timer_generic.cc:467]       TIMER 0x7ffa64003648: CANCEL pending=true
I1022 10:28:39.705345415   24227 tcp_posix.cc:265]           TCP:0x7ffa640011b0 notify_on_read
I1022 10:28:39.705356748   24227 connectivity_state.cc:100]  CONWATCH: 0x7ffa640021a8 server_transport: from READY [cur=READY] notify=0x7ffa640042e0
I1022 10:28:39.705368123   24227 timer_generic.cc:365]       TIMER 0x7ffa64003648: SET 7214812 now 14812 call 0x7ffa640035a8[0x7ffa78aff900]
I1022 10:28:39.705379456   24227 timer_generic.cc:401]         .. add to shard 7 with queue_deadline_cap=15009 => is_first_timer=false
D1022 10:28:39.705402123   24227 flow_control.cc:113]        0x7ffa64003368[0][svr] | t updt sent | trw:                         65535, tlw:                       4194304, taw:              65535 -> 4194304, srw:                              , slw:                              , saw:                              
I1022 10:28:39.705433539   24227 writing.cc:116]             SERVER: Ping sent [ipv4:127.0.0.1:35425]: 2/2
I1022 10:28:39.705447205   24227 chttp2_transport.cc:839]    W:0x7ffa64001f00 SERVER [ipv4:127.0.0.1:35425] state WRITING+MORE -> WRITING [begin write in current thread]
I1022 10:28:39.705460205   24227 tcp_posix.cc:1058]          WRITE 0x7ffa640011b0 (peer=ipv4:127.0.0.1:35425)
D1022 10:28:39.705495954   24227 tcp_posix.cc:1062]          DATA: 00 00 18 04 00 00 00 00 00 00 04 00 40 00 00 00 05 00 40 00 00 00 06 00 00 20 00 fe 03 00 00 00 01 '............@.....@...... .......'
I1022 10:28:39.705507371   24227 tcp_posix.cc:1058]          WRITE 0x7ffa640011b0 (peer=ipv4:127.0.0.1:35425)
D1022 10:28:39.705538287   24227 tcp_posix.cc:1062]          DATA: 00 00 04 08 00 00 00 00 00 00 3f 00 01 00 00 08 06 00 00 00 00 00 00 '..........?............'
I1022 10:28:39.705549662   24227 tcp_posix.cc:1058]          WRITE 0x7ffa640011b0 (peer=ipv4:127.0.0.1:35425)
D1022 10:28:39.705561036   24227 tcp_posix.cc:1062]          DATA: 00 00 00 00 00 00 00 '.......'
I1022 10:28:39.705593577   24227 tcp_posix.cc:1096]          write: "No Error"
I1022 10:28:39.705604952   24227 chttp2_transport.cc:2660]   ipv4:127.0.0.1:35425: Start BDP ping err="No Error"
I1022 10:28:39.705616327   24227 timer_generic.cc:467]       TIMER 0x7ffa64003648: CANCEL pending=true
I1022 10:28:39.705627660   24227 bdp_estimator.h:66]         bdp[ipv4:127.0.0.1:35425]:start acc=0 est=65536
I1022 10:28:39.705650451   24227 chttp2_transport.cc:839]    W:0x7ffa64001f00 SERVER [ipv4:127.0.0.1:35425] state WRITING -> IDLE [finish writing]
I1022 10:28:39.705674784   24227 timer_generic.cc:365]       TIMER 0x7ffa64003648: SET 7214812 now 14812 call 0x7ffa640035a8[0x7ffa78aff900]
I1022 10:28:39.705686117   24227 timer_generic.cc:401]         .. add to shard 7 with queue_deadline_cap=15009 => is_first_timer=false
I1022 10:28:39.732094959   24227 tcp_posix.cc:605]           TCP:0x7ffa640011b0 got_read: "No Error"
I1022 10:28:39.732152375   24227 tcp_posix.cc:590]           TCP:0x7ffa640011b0 alloc_slices
I1022 10:28:39.732163750   24227 resource_quota.cc:889]      RQ anonymous_pool_7ffa64000fb0 ipv4:127.0.0.1:35425: alloc 8192; free_pool -> -8192
I1022 10:28:39.732175166   24227 resource_quota.cc:321]      RQ: check allocation for user 0x7ffa640014a0 shutdown=0 free_pool=-8192
I1022 10:28:39.732186499   24227 resource_quota.cc:347]      RQ anonymous_pool_7ffa64000fb0 ipv4:127.0.0.1:35425: grant alloc 8192 bytes; rq_free_pool -> 9223372036854767615
I1022 10:28:39.732197832   24227 tcp_posix.cc:571]           TCP:0x7ffa640011b0 read_allocation_done: "No Error"
I1022 10:28:39.732209207   24227 tcp_posix.cc:401]           TCP:0x7ffa640011b0 call_cb 0x7ffa64002040 0x7ffa78b01360:0x7ffa64001f00
I1022 10:28:39.732222165   24227 tcp_posix.cc:404]           READ 0x7ffa640011b0 (peer=ipv4:127.0.0.1:35425) error="No Error"
D1022 10:28:39.732271497   24227 tcp_posix.cc:410]           DATA: 50 4f 53 54 20 2f 64 69 63 6f 6d 2e 44 69 63 6f 6d 2f 53 61 79 48 65 6c 6c 6f 20 48 54 54 50 2f 31 2e 31 0d 0a 48 6f 73 74 3a 20 31 32 37 2e 30 2e 30 2e 31 3a 35 30 30 35 31 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a 20 67 72 70 63 2d 64 6f 74 6e 65 74 2f 32 2e 32 34 2e 30 2e 30 0d 0a 54 45 3a 20 74 72 61 69 6c 65 72 73 0d 0a 67 72 70 63 2d 61 63 63 65 70 74 2d 65 6e 63 6f 64 69 6e 67 3a 20 69 64 65 6e 74 69 74 79 2c 67 7a 69 70 0d 0a 54 72 61 6e 73 66 65 72 2d 45 6e 63 6f 64 69 6e 67 3a 20 63 68 75 6e 6b 65 64 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e 2f 67 72 70 63 0d 0a 0d 0a 35 0d 0a 00 00 00 00 0f 0d 0a 46 0d 0a 0a 0d 47 72 65 65 74 65 72 43 6c 69 65 6e 74 0d 0a 'POST /dicom.Dicom/SayHello HTTP/1.1..Host: 127.0.0.1:50051..User-Agent: grpc-dotnet/2.24.0.0..TE: trailers..grpc-accept-encoding: identity,gzip..Transfer-Encoding: chunked..Content-Type: application/grpc....5.........F....GreeterClient..'
I1022 10:28:39.732354288   24227 chttp2_transport.cc:2866]   transport 0x7ffa64001f00 set connectivity_state=4
I1022 10:28:39.732365662   24227 connectivity_state.cc:147]  SET: 0x7ffa640021a8 server_transport: READY --> SHUTDOWN [close_transport]
I1022 10:28:39.732377037   24227 connectivity_state.cc:160]  NOTIFY: 0x7ffa640021a8 server_transport: 0x7ffa640042e0
I1022 10:28:39.732388370   24227 timer_generic.cc:467]       TIMER 0x7ffa64003648: CANCEL pending=true
I1022 10:28:39.732433744   24227 chttp2_transport.cc:1900]   perform_transport_op[t=0x7ffa64001f00]: SET_ACCEPT_STREAM:(nil)((nil),...)
I1022 10:28:39.732467744   24227 tcp_posix.cc:854]           TCP:0x7ffa640011b0 got_error: {"created":"@1571754519.732422411","description":"FD Shutdown","file":"src/core/lib/iomgr/lockfree_event.cc","file_line":194,"referenced_errors":[{"created":"@1571754519.732342913","description":"Failed parsing HTTP/2","file":"src/core/ext/transport/chttp2/transport/chttp2_transport.cc","file_line":2582,"grpc_status":14,"referenced_errors":[{"created":"@1571754519.732294330","description":"Connect string mismatch: expected 'R' (82) got 'O' (79) at byte 1","file":"src/core/ext/transport/chttp2/transport/parsing.cc","file_line":97}]}]}
I1022 10:28:39.732498535   24227 chttp2_transport.cc:2676]   ipv4:127.0.0.1:35425: Complete BDP ping err={"created":"@1571754519.732342913","description":"Failed parsing HTTP/2","file":"src/core/ext/transport/chttp2/transport/chttp2_transport.cc","file_line":2582,"referenced_errors":[{"created":"@1571754519.732294330","description":"Connect string mismatch: expected 'R' (82) got 'O' (79) at byte 1","file":"src/core/ext/transport/chttp2/transport/parsing.cc","file_line":97}]}
I1022 10:28:39.732521285   24227 init.cc:211]                grpc_shutdown(void)
I1022 10:28:39.732532618   24227 resource_quota.cc:547]      RU shutdown 0x7ffa640014a0
I1022 10:28:39.902870280   24226 timer_manager.cc:204]       wait ended: was_timed:1 kicked:0

这是我的.NET 3.0项目。

代码语言:javascript
复制
using System;
using System.Threading.Tasks;
using Grpc.Net.Client;
using Dicom;

namespace Client
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var channel = GrpcChannel.ForAddress("http://127.0.0.1:50051");
            var client = new Dicom.Dicom.DicomClient(channel);

            var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
            Console.WriteLine("Greeting: " + reply.Message);
        }
    }
}
代码语言:javascript
复制
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Protobuf Include="../../../proto/dicom.proto" GrpcServices="Client" Link="Protos\dicom.proto" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Google.Protobuf" Version="3.10.0" />
    <PackageReference Include="Grpc.Net.Client" Version="2.24.0" />
    <PackageReference Include="Grpc.Tools" Version="2.24.0" />
  </ItemGroup>

</Project>

另外,这是我的proto文件:

代码语言:javascript
复制
syntax = "proto3";

package dicom;

// The greeting service definition.
service Dicom {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply);
  rpc SayHellos (HelloRequest) returns (stream HelloReply);
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

UPDATE:我更改为使用原始gRPC团队中的.NET库,它可以工作。下面是用于调试问题的新服务器端日志(来自C++)。

https://pastebin.com/cSWNhVvT

EN

回答 1

Stack Overflow用户

发布于 2019-10-22 18:53:38

我认为您的问题是在使用AppContext时需要设置http标志

代码语言:javascript
复制
// This switch must be set before creating the GrpcChannel/HttpClient.
AppContext.SetSwitch(
    "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

https://learn.microsoft.com/en-us/aspnet/core/grpc/troubleshoot?view=aspnetcore-3.0#call-insecure-grpc-services-with-net-core-client

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58506709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档