質問編集履歴

5

応答結果の読み取り方をBufferedInputStreamに変更しました。

2019/08/09 03:06

投稿

Mozart
Mozart

スコア25

test CHANGED
File without changes
test CHANGED
@@ -216,7 +216,9 @@
216
216
 
217
217
  os.write(bb.array());
218
218
 
219
+ os.flush();
220
+
219
- InputStream is = socket.getInputStream();
221
+ InputStream is = new BufferedInputStream(socket.getInputStream());
220
222
 
221
223
  int c = 0;
222
224
 

4

応答結果の出力方法を変更しました。

2019/08/09 03:06

投稿

Mozart
Mozart

スコア25

test CHANGED
File without changes
test CHANGED
@@ -50,6 +50,14 @@
50
50
 
51
51
  という結果となりました。
52
52
 
53
+
54
+
55
+ 出力を16進数に変更したところ、
56
+
57
+ 15 3 3 0 2 2 A
58
+
59
+ という結果となりました。
60
+
53
61
  ```
54
62
 
55
63
 
@@ -182,13 +190,13 @@
182
190
 
183
191
  //アプリケーションID
184
192
 
185
- bb.put((byte) 0x00);
193
+ bb.put((byte) 0xF0);
186
194
 
187
195
 
188
196
 
189
197
  //モード
190
198
 
191
- bb.put((byte) 0x01);
199
+ bb.put((byte) 0xF0);
192
200
 
193
201
 
194
202
 
@@ -214,7 +222,7 @@
214
222
 
215
223
  while((c = is.read()) != -1) {
216
224
 
217
- System.out.println(c);
225
+ System.out.printf("%2X", c);
218
226
 
219
227
  }
220
228
 

3

読み込み方法をinputstream直からbyteを読む方向に変更いたしました。

2019/08/08 08:43

投稿

Mozart
Mozart

スコア25

test CHANGED
File without changes
test CHANGED
@@ -40,6 +40,16 @@
40
40
 
41
41
  何が原因か特定できずにおります。
42
42
 
43
+
44
+
45
+
46
+
47
+ byteで直接読み込むように変更したところ、
48
+
49
+ 21 3 3 0 2 2 10
50
+
51
+ という結果となりました。
52
+
43
53
  ```
44
54
 
45
55
 
@@ -196,28 +206,22 @@
196
206
 
197
207
  DataOutputStream os = new DataOutputStream(socket.getOutputStream());
198
208
 
199
- BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream(), "sjis"));
200
-
201
209
  os.write(bb.array());
202
210
 
211
+ InputStream is = socket.getInputStream();
212
+
203
- String data = null;
213
+ int c = 0;
204
-
214
+
205
- if((data = br.readLine()) != null) {
215
+ while((c = is.read()) != -1) {
206
-
207
- byte[] byte_h = data.getBytes("sjis");
216
+
208
-
209
- for(byte b : byte_h) {
210
-
211
- System.out.println(b);
217
+ System.out.println(c);
212
-
213
- }
214
218
 
215
219
  }
216
220
 
221
+ is.close();
222
+
217
223
  os.close();
218
224
 
219
- br.close();
220
-
221
225
  socket.close();
222
226
 
223
227
 

2

TTCをSHと開局制御電文の間に追加しました。

2019/08/08 06:41

投稿

Mozart
Mozart

スコア25

test CHANGED
File without changes
test CHANGED
@@ -50,17 +50,15 @@
50
50
 
51
51
  ```java
52
52
 
53
- ByteBuffer bb = ByteBuffer.allocate(72);
53
+ ByteBuffer bb = ByteBuffer.allocate(77);
54
-
55
-
56
-
57
- // #### サブレイヤヘッダ ####
54
+
55
+
58
56
 
59
57
  //メッセージ長
60
58
 
61
59
  bb.put((byte) 0x00);
62
60
 
63
- bb.put((byte) 0x00);
61
+ bb.put((byte) 0x4D);
64
62
 
65
63
 
66
64
 
@@ -72,128 +70,150 @@
72
70
 
73
71
  for(int i = 0; 5 > i; i++) {
74
72
 
73
+ bb.put((byte) 0x00);
74
+
75
+ }
76
+
77
+
78
+
79
+ //#### TTC ####
80
+
81
+ //情報区分
82
+
83
+ bb.put((byte) 0x00);
84
+
85
+
86
+
87
+ //テキストシークェンス番号
88
+
89
+ bb.putShort((short) 0);
90
+
91
+
92
+
93
+ //テキスト長
94
+
95
+ bb.putShort((short) 69);
96
+
97
+
98
+
99
+ // #### メッセージ ####
100
+
101
+ // #### 開局制御電文 ####
102
+
103
+ //電文区分
104
+
105
+ bb.put((byte) 0x00);
106
+
107
+
108
+
109
+ //処理結果
110
+
111
+ bb.put((byte) 0x00);
112
+
113
+
114
+
115
+ //センターコード
116
+
117
+ bb.put((byte) 0x00);
118
+
119
+ bb.put((byte) 0x00);
120
+
121
+ bb.put((byte) 0x00);
122
+
123
+ bb.put((byte) 0x00);
124
+
125
+ bb.put((byte) 0x00);
126
+
127
+ bb.put((byte) 0x00);
128
+
129
+ bb.put((byte) 0x00);
130
+
131
+
132
+
133
+ //コード
134
+
135
+ bb.put((byte) 0x00);
136
+
137
+ bb.put((byte) 0x00);
138
+
139
+ bb.put((byte) 0x00);
140
+
141
+ bb.put((byte) 0x00);
142
+
143
+ bb.put((byte) 0x00);
144
+
145
+ bb.put((byte) 0x00);
146
+
147
+ bb.put((byte) 0x00);
148
+
149
+
150
+
151
+ //年月日
152
+
153
+ bb.put((byte) 0x00);
154
+
155
+ bb.put((byte) 0x00);
156
+
157
+ bb.put((byte) 0x00);
158
+
159
+ bb.put((byte) 0x00);
160
+
161
+ bb.put((byte) 0x00);
162
+
163
+ bb.put((byte) 0x00);
164
+
165
+
166
+
167
+ //パスワード
168
+
169
+ bb.put("xxxxxx".getBytes("CP037"));
170
+
171
+
172
+
173
+ //アプリケーションID
174
+
175
+ bb.put((byte) 0x00);
176
+
177
+
178
+
179
+ //モード
180
+
181
+ bb.put((byte) 0x01);
182
+
183
+
184
+
185
+ for(int i = 0; 34 > i; i++) {
186
+
75
187
  bb.put((byte) 0x00);
76
188
 
77
189
  }
78
190
 
79
-
80
-
81
- // #### メッセージ ####
82
-
83
- //電文区分
191
+ bb.flip();
192
+
193
+
194
+
84
-
195
+ Socket socket = new Socket("xxx.xxx.xxx.xxx", xxx);
196
+
197
+ DataOutputStream os = new DataOutputStream(socket.getOutputStream());
198
+
199
+ BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream(), "sjis"));
200
+
85
- bb.put((byte) 0x00);
201
+ os.write(bb.array());
86
-
87
-
88
-
89
- //処理結果
202
+
90
-
91
- bb.put((byte) 0x00);
203
+ String data = null;
92
-
93
-
94
-
95
- //センターコード
204
+
96
-
97
- bb.put((byte) 0x00);
205
+ if((data = br.readLine()) != null) {
98
-
99
- bb.put((byte) 0x00);
206
+
100
-
101
- bb.put((byte) 0x00);
102
-
103
- bb.put((byte) 0x00);
104
-
105
- bb.put((byte) 0x00);
106
-
107
- bb.put((byte) 0x00);
108
-
109
- bb.put((byte) 0x00);
110
-
111
-
112
-
113
- //コード
114
-
115
- bb.put((byte) 0x00);
116
-
117
- bb.put((byte) 0x00);
118
-
119
- bb.put((byte) 0x00);
120
-
121
- bb.put((byte) 0x00);
122
-
123
- bb.put((byte) 0x00);
124
-
125
- bb.put((byte) 0x00);
126
-
127
- bb.put((byte) 0x00);
128
-
129
-
130
-
131
- //年月日
132
-
133
- bb.put((byte) 0x00);
134
-
135
- bb.put((byte) 0x00);
136
-
137
- bb.put((byte) 0x00);
138
-
139
- bb.put((byte) 0x00);
140
-
141
- bb.put((byte) 0x00);
142
-
143
- bb.put((byte) 0x00);
144
-
145
-
146
-
147
- //パスワード
148
-
149
- bb.put("xxxxxx".getBytes("CP037"));
207
+ byte[] byte_h = data.getBytes("sjis");
150
-
151
-
152
-
153
- //アプリケーションID
208
+
154
-
155
- bb.put((byte) 0x00);
156
-
157
-
158
-
159
- //モード
160
-
161
- bb.put((byte) 0x01);
162
-
163
-
164
-
165
- for(int i = 0; 34 > i; i++) {
209
+ for(byte b : byte_h) {
166
-
210
+
167
- bb.put((byte) 0x00);
211
+ System.out.println(b);
212
+
213
+ }
168
214
 
169
215
  }
170
216
 
171
- bb.flip();
172
-
173
-
174
-
175
- Socket socket = new Socket("xxx.xxx.xxx.xxx", xxx);
176
-
177
- DataOutputStream os = new DataOutputStream(socket.getOutputStream());
178
-
179
- BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream(), "sjis"));
180
-
181
- os.write(bb.array());
182
-
183
- String data = null;
184
-
185
- if((data = br.readLine()) != null) {
186
-
187
- byte[] byte_h = data.getBytes("sjis");
188
-
189
- for(byte b : byte_h) {
190
-
191
- System.out.println(b);
192
-
193
- }
194
-
195
- }
196
-
197
217
  os.close();
198
218
 
199
219
  br.close();

1

情報を編集しました。

2019/08/08 00:42

投稿

Mozart
Mozart

スコア25

test CHANGED
File without changes
test CHANGED
@@ -172,7 +172,7 @@
172
172
 
173
173
 
174
174
 
175
- Socket socket = new Socket("zot.e-mednet.jp", 443);
175
+ Socket socket = new Socket("xxx.xxx.xxx.xxx", xxx);
176
176
 
177
177
  DataOutputStream os = new DataOutputStream(socket.getOutputStream());
178
178