forked from openlcb/OpenLCB_Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamReceiver.java
More file actions
46 lines (38 loc) · 1.23 KB
/
StreamReceiver.java
File metadata and controls
46 lines (38 loc) · 1.23 KB
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
package org.openlcb.implementations;
import org.openlcb.*;
/**
* Example of receiving a OpenLCB stream.
*
* @author Bob Jacobsen Copyright 2009
*/
public class StreamReceiver extends MessageDecoder {
public StreamReceiver(NodeID here, NodeID far, Connection c) {
this.here = here;
this.far = far;
this.connection = c;
}
NodeID here;
NodeID far;
Connection connection;
byte sourceStreamID;
byte destStreamID = 3; // notional value
/**
* Handle "Stream Init Request" message
*/
public void handleStreamInitiateRequest(StreamInitiateRequestMessage msg, Connection sender){
// send reply with same length
int len = msg.getBufferSize();
sourceStreamID = msg.getSourceStreamID();
// flags are 0
Message m = new StreamInitiateReplyMessage(here, far, 0, len, sourceStreamID, destStreamID);
connection.put(m, this);
}
/**
* Handle "Stream Data Send" message
*/
public void handleStreamDataSend(StreamDataSendMessage msg, Connection sender){
// send proceed reply
Message m = new StreamDataProceedMessage(here, far, sourceStreamID, destStreamID, 0);
connection.put(m, this);
}
}