2
2
3
3
import java .io .DataOutputStream ;
4
4
import java .io .IOException ;
5
+ import java .io .InputStream ;
5
6
import java .io .OutputStream ;
6
7
import java .net .Socket ;
7
8
8
9
public class CQCSession {
9
10
10
11
private Socket socket ;
11
12
private OutputStream os ;
13
+ private InputStream is ;
12
14
private short appId ;
13
15
14
16
public CQCSession () {
@@ -24,13 +26,34 @@ public void connect(String host, int port) throws IOException {
24
26
}
25
27
26
28
public void sendHello () throws IOException {
27
- sendCqcHeadercd op - (Protocol .CQC_TP_HELLO , 0 );
29
+ sendCqcHeader (Protocol .CQC_TP_HELLO , 0 );
28
30
}
29
31
30
32
public void createQubit () throws IOException {
31
33
sendSimpleCommand (Protocol .CQC_CMD_NEW , (short )0 );
32
34
}
33
35
36
+ private void sendComman () {
37
+
38
+ }
39
+ public void createEPR (String name ) throws IOException {
40
+ sendCommand (Protocol .CQC_CMD_EPR ,(short )0 ,true ,false , true , 12 );
41
+ // sendSimpleCommand(Protocol.CQC_CMD_EPR, (short)0);
42
+ }
43
+
44
+ public ResponseMessage readMessage () throws IOException {
45
+ if (is == null ) {
46
+ is = socket .getInputStream ();
47
+ }
48
+ byte [] msg = new byte [256 ];
49
+ int len = is .read (msg );
50
+ if (len < 8 ) {
51
+ throw new IOException ("Can't read message if it has less than 8 bytes (got " +len +")" );
52
+ }
53
+ ResponseMessage answer = new ResponseMessage (msg , len );
54
+ return answer ;
55
+ }
56
+
34
57
static short appIdCounter = 0 ;
35
58
36
59
private static synchronized short getNextAppId () {
@@ -49,15 +72,20 @@ private void sendCqcHeader(byte type, int len) throws IOException {
49
72
dos .writeShort (appId );
50
73
dos .writeInt (len );
51
74
dos .flush ();
52
- // byte[] data = new byte[8];
53
- // data[0] = Protocol.VERSION;
54
- // data[1] = type;
55
- // data[2] = (byte)(appId & 0xff);
56
- // data[3] = (byte)((appId >> 8) & 0xff);
57
-
58
75
}
76
+
59
77
private void sendCommand (byte command , short qubit_id , boolean notify , boolean action , boolean block , int length ) throws IOException {
60
78
sendCqcHeader (Protocol .CQC_TP_COMMAND , length );
79
+ if (command == Protocol .CQC_CMD_EPR ) {
80
+ DataOutputStream dos = new DataOutputStream (os );
81
+ dos .writeShort (0 ); // qubit_id
82
+ dos .writeByte (command );
83
+ dos .writeByte (0 );
84
+ dos .writeShort (1 );
85
+ dos .writeShort (2 );
86
+ dos .writeInt (4 );
87
+ dos .flush ();
88
+ }
61
89
62
90
}
63
91
0 commit comments