Comments (10)
I'm having similar problem.
I have already built websockets server which was built for JS primarily and I'm reusing client session cookies from simple HTTP request when client loaded the page. When client socket connects to the server I capture that cookie and use it to identify the user. This makes handling users super simple, as there is libraries for Node.js that can essentially handle session cookies for you.
Unfortunately once I connect to server from android, I have no cookies set, even if I try to make HTTP connection before I connect to server.
P.S.
I'm just starting to learn Android dev and the stuff above that I wrote might make little to no sense at all, in which case I would gladly clarify my use case.
Thanks for your job on this socket.io client!
from socket.io-client-java.
On just released v0.1.3, you can access to http headers like the following:
socket.io().on(Manager.EVENT_TRANSPORT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Transport transport = (Transport)args[0];
transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() {
@Override
public void call(Object... args) {
@SuppressWarnings("unchecked")
Map<String, String> headers = (Map<String, String>)args[0];
// set header
headers.put("X-SocketIO", "hi");
}
}).on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() {
@Override
public void call(Object... args) {
@SuppressWarnings("unchecked")
Map<String, String> headers = (Map<String, String>)args[0];
// get header
String value = headers.get("X-SocketIO");
}
});
}
});
from socket.io-client-java.
@nkzawa Will this add "X-SocketIO": "hi" to each socket.io request that I will send?
I'm using passport.js with https://github.com/jfromaniello/passport.socketio.
from socket.io-client-java.
@danpe yes.
from socket.io-client-java.
Can I give the socket a java.net.CookieManager / java.net.CookieStore to use ?
Or I should implement my own function to read the and write to the cookie store using the example you gave ?
If so, do you want me to add this feature as a pull request ?
from socket.io-client-java.
@danpe Unfortunately, you need to implement your own.
I don't have any thought to add such feature to the library for now, since I'd like to keep it simple as much as possible. Though it depends on how many requests we get.
Thank you for your suggestion anyway!
from socket.io-client-java.
use url param to send cookie instead of send headers directly will better :D
from socket.io-client-java.
Need cookie store! :(
from socket.io-client-java.
if you use this, you will probably be sad, as I was when I found out that the JavaScript socket.io client will never support sending headers.
see:
socketio/socket.io-client#648 (comment)
In my case, i need to rewrite my API to handle authentication in a separate step -- after connecting.
from socket.io-client-java.
@nkzawa Your example seems to work except that the Transport headers are actually a Map, List> in the PollingXHR class.
Not sure why they need to be a Map of Lists not just a Map of Strings?
from socket.io-client-java.
Related Issues (20)
- io.socket.client.IO::managers leaks resources HOT 1
- 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
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.