Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/org/java_websocket/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,21 @@ enum READYSTATE {
* @return Returns the decoded path component of this URI.
**/
String getResourceDescriptor();

/**
* Setter for an attachment on the socket connection.
* The attachment may be of any type.
*
* @param attachment The object to be attached to the user
* @since 1.3.7
**/
<T> void setAttachment(T attachment);

/**
* Getter for the connection attachment.
*
* @return Returns the user attachment
* @since 1.3.7
**/
<T> T getAttachment();
}
17 changes: 17 additions & 0 deletions src/main/java/org/java_websocket/WebSocketImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ public class WebSocketImpl implements WebSocket {
*/
private PingFrame pingFrame;

/**
* Attribute to store connection attachment
* @since 1.3.7
*/
private Object attachment;

/**
* Creates a websocket with server role
*
Expand Down Expand Up @@ -799,4 +805,15 @@ public WebSocketListener getWebSocketListener() {
return wsl;
}

@Override
@SuppressWarnings("unchecked")
public <T> T getAttachment() {
return (T) attachment;
}

@Override
public <T> void setAttachment(T attachment) {
this.attachment = attachment;
}

}