Comments (10)
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.
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.
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.
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.
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.
@josephkandi Did you get it working ?
from socket.io-client-java.
@akprats33 Nope i did not
from socket.io-client-java.
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.
@ akprats33 No, no lo hice
Lograste hacerlo funcionar?
from socket.io-client-java.
This does not work for me.
from socket.io-client-java.
Related Issues (20)
- socket.io client sometimes sends arrays wrong HOT 5
- can i use multiple socket connection ?
- Android 13 not available HOT 1
- It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible HOT 2
- sendBuffer should be accessible
- Getting EVENT_CONNECT_ERROR from Android to Node HOT 1
- Change/update auth or query or extraheaders containing token after connection HOT 1
- Is this project Still Alive? HOT 3
- How to listen to Manager events? (Socket events are working) HOT 2
- Straightforward logging option for Android
- testDecodeError function in Helpers.java error message clean up HOT 2
- Report: ConcurrentModificationException when use AckWithTimout...
- Connection state recovery HOT 1
- NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference HOT 1
- Unable to emit JSON object instead it is emitting Stringified Json in Client Version - 1.0.2 HOT 1
- Implement Connection State Recovery
- it throws java.lang.ClassCastException when sending nested json data. HOT 1
- in the this one the depencies are not dwonloading for me
- Android 14 not compatible with version 2.1.0
- received disconnect event. and socket closed.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket.io-client-java.