Code Monkey home page Code Monkey logo

Comments (2)

Philip-Wu avatar Philip-Wu commented on July 18, 2024

I'm getting a similar error on a different IP:

SocketException: Failed host lookup: 'http://10.0.2.2:8080/stomp' (OS Error: No address associated with hostname, errno = 7)
E/flutter (29911): #0      _NativeSocket.lookup.<anonymous closure> (dart:io/runtime/binsocket_patch.dart:368:9)
E/flutter (29911): #1      _RootZone.runUnary (dart:async/zone.dart:1379:54)
E/flutter (29911): #2      _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
E/flutter (29911): #3      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)

from web_socket_channel.

tduchateau avatar tduchateau commented on July 18, 2024

I was getting a similar issue with authentication. The following did the trick for me with Spring Security and JWT-based authentication.

Update the modified version custom_stomp posted here (thx for that @xbassols!) as follows:

Future<StompClient> connect(String url,
    {String host,
      String login,
      String passcode,
      Map<String, dynamic> headers, // <--- here
      List<int> heartbeat,
      void onConnect(StompClient client, Map<String, String> headers), // <--- here
      void onDisconnect(StompClient client),
      void onError(StompClient client, String message, String detail,
          Map<String, String> headers),
      void onFault(StompClient client, error, stackTrace)}) async =>
    connectWith(await IOWebSocketChannel.connect(url,
        headers: headers), // <--- and here
        host: host,
        login: login,
        passcode: passcode,
        heartbeat: heartbeat,
        onConnect: onConnect,
        onDisconnect: onDisconnect,
        onError: onError,
        onFault: onFault);

Then you can pass authentication headers on connect.

Future<StompClient> clientFuture = customStomp.connect(
        'ws://localhost:8080/ws',
        headers: {'Authorization': 'Bearer $accessToken'},
        onConnect: ...

Then these headers will be intercepted by Spring to perform authentication. Hope it helps!

from web_socket_channel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.