aboutsummaryrefslogtreecommitdiff
path: root/src/com/juick/jabber/ws/SocketSubscribed.java
blob: 6144380cb3a878193433965e3dfd1710da5368dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.juick.jabber.ws;

import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 *
 * @author ugnich
 */
public class SocketSubscribed {

    public SocketChannel sock = null;
    public String clientName = null;
    public int VUID = 0;
    public int UID = 0;
    public int MID = 0;
    public boolean allMessages = false;
    public boolean allReplies = false;
    public long tsConnected;
    public long tsLastData;

    public SocketSubscribed(SocketChannel sock, String clientName, int VUID) {
        this.sock = sock;
        this.clientName = clientName;
        this.VUID = VUID;
        tsConnected = tsLastData = System.currentTimeMillis();
    }

    public boolean sendByteBuffer(ByteBuffer bb) {
        boolean ret = false;
        bb.rewind();
        try {
            sock.write(bb);
            ret = true;
        } catch (Exception e) {
            close();
        }
        return ret;
    }

    public void close() {
        try {
            sock.socket().close();
        } catch (Exception e) {
        }
        try {
            sock.close();
        } catch (Exception e) {
        }
    }
}