Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: Starting connection with transfer format 'TransferFormat.text'. #15

Closed
xuanhe168 opened this issue Jun 5, 2020 · 2 comments

Comments

@xuanhe168
Copy link

{Error info}_20200605140836

code:

class HomeState extends State<MyHomePage> {
  StringBuffer remoteMsg = StringBuffer();
  HubConnection hubConnection = HubConnectionBuilder().withUrl('http://xxx.xxx/:8000/api/chatHub',
      HttpConnectionOptions(
        transport:HttpTransportType.none,
        logging: (level, message) => print("message: $message"),
        accessTokenFactory:() => Future.value("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW4iLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImFkbWluIiwianRpIjoiMSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvZXhwaXJhdGlvbiI6IjYvNS8yMCAyOjQwOjMzIFBNIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW4iLCJuYmYiOjE1OTEzMzU2MzMsImV4cCI6MTU5MTMzOTIzMywiaXNzIjoiT0EuUlNJLkJhY2tlbmQiLCJhdWQiOiJ3ciJ9.gKaIBDSF0MLJ5b6j7iiWKCeVvQJPMkqYJOuwPW_Yncw")
      )).build();

  @override
  void initState(){
    super.initState();
    init();
  }

  init() async {
    hubConnection.on('ReceiveMessage', (message) {
      setState(() {
        message.forEach((v) => remoteMsg.write(v));
        print(message.toString());
      });
    });
    try{
      await hubConnection.start();
      print("连接成功...");
    }catch(e){
      print("连接失败...");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text("message from server: ${remoteMsg.toString()}"),
          TextField(
            decoration:InputDecoration(
              hintText:"Enter some text",
            ),
            onSubmitted:((v)async => await hubConnection.invoke('SendMessage', args: ['Flutter', v])),
          ),
        ],
      ),
    );
  }
}
@jamiewest
Copy link
Owner

Possibly related to #14, also I don't think you need to return a Future to the accessTokenFactory.

@xuanhe168
Copy link
Author

I added ''transport: HttpTransportType.longPolling,'' to HttpConnectionOptions solved my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants