Code Monkey home page Code Monkey logo

Comments (10)

josephkandi avatar josephkandi commented on May 18, 2024 3

Why was this issue closed? I cant connect to my socket.io server if i am behind a proxy that requires a username and password. If i use the browser, the browsers shows a popup where i put in the username and password and i can connect to the chat web front-end. How i setup the client so that i can pass the username and password or so that it uses the system's proxy settings. The system proxy settings says they are for the bowser and some apps might not use them.

from socket.io-client-java.

nkzawa avatar nkzawa commented on May 18, 2024

Hi, I'm not familiar with that situation, but I think you don't need anything special.
Socket.IO and this library treat only HTTP and WebSocket, so it's ok if the proxy server could handle them.

from socket.io-client-java.

sojharo avatar sojharo commented on May 18, 2024

Proxy server just blocks the socket connection when I used another java websocket library. This is why I came here looking for any other library. I am always behind a proxy server. Let me use this library and I will let you know if this library works behind the proxy server or not.

from socket.io-client-java.

FaizVisram avatar FaizVisram commented on May 18, 2024

I use Charles Proxy (using the proxy settings in the device's System > Wi-Fi settings with this library. Though I can't actually see the data being transferred in Charles, the library still functions as it should.

from socket.io-client-java.

sojharo avatar sojharo commented on May 18, 2024

It is because library doesn't know that there is a proxy and it should be sending or receiving the data through that proxy. Just like in Windows Firefox, we need to tell the software that it should "use system proxy", similarly, any application which connects to Internet should be able to know whether there is a proxy set on device or not. If there is a proxy set on the device application should also use that proxy. Other socket libraries I have used doesn't have this feature. They don't care whether android device is behind proxy or not. I haven't tested this library yet. In couple of days, I will switch to this library in my project.

from socket.io-client-java.

akprats33 avatar akprats33 commented on May 18, 2024

@josephkandi Did you get it working ?

from socket.io-client-java.

josephkandi avatar josephkandi commented on May 18, 2024

@akprats33 Nope i did not

from socket.io-client-java.

akprats33 avatar akprats33 commented on May 18, 2024

Just in case anyone is still stuck with proxy, I got it working with the following configuration -

public connect() {
    String httpsProxyHost = getSystemProperty("https.proxyHost");
    this.protocol = StringUtils.isNotEmpty(httpsProxyHost) ? Protocol.HTTPS : Protocol.HTTP;

    OkHttpClient okHttpClient = this.getHttpClientBuilder()
      .build();

    IO.setDefaultOkHttpCallFactory(okHttpClient);
    IO.setDefaultOkHttpWebSocketFactory(okHttpClient);

   try {
      socket = IO.socket(<socket url>);
      socket.connect();
    } catch (URISyntaxException e) {
      throw new RuntimeException("Error in initializing Socket.", e);
    }
}

  /**
   * Generate client builder with proxy settings applied
   *
   * @return
   */
  private OkHttpClient.Builder getHttpClientBuilder() {
    OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
      .pingInterval(10000, TimeUnit.MILLISECONDS);

    String proxyHostProperty = getProxyHostProperty();
    String proxyPortProperty = getProxyPortProperty();
    if (StringUtils.isEmpty(proxyHostProperty) ||
      StringUtils.isEmpty(proxyPortProperty)) return clientBuilder;

    int proxyPort = Integer.parseInt(proxyPortProperty);
    Proxy networkProxy =
      new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHostProperty, proxyPort));
    // set proxy
    clientBuilder.proxy(networkProxy);

    String proxyUser = getProxyUsernameProperty();
    String proxyPassword = getProxyPasswordProperty();

    // no authentication at all
    if (StringUtils.isEmpty(proxyUser)) return clientBuilder;

    Authenticator proxyAuthenticator = new Authenticator() {
      @Nullable
      @Override
      public Request authenticate(Route route, Response response) throws IOException {
        String credential = Credentials.basic(proxyUser, proxyPassword);
        Request authRequest = response.request().newBuilder()
          .header("Proxy-Authorization", credential)
          .build();

        ResponseBody responseBody = response.body();
        if (responseBody != null) responseBody.close();
        return authRequest;
      }
    };
    clientBuilder.proxyAuthenticator(proxyAuthenticator);

    return clientBuilder;
  }

from socket.io-client-java.

jorgepbarrera38 avatar jorgepbarrera38 commented on May 18, 2024

@ akprats33 No, no lo hice

Lograste hacerlo funcionar?

from socket.io-client-java.

lochsenfeld avatar lochsenfeld commented on May 18, 2024

This does not work for me.

from socket.io-client-java.

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.