質問編集履歴
7
ソースコードの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -136,10 +136,6 @@
|
|
136
136
|
|
137
137
|
System.out.println(cIU.current_longitude);
|
138
138
|
|
139
|
-
System.out.println(cIU.destination_latitude);
|
140
|
-
|
141
|
-
System.out.println(cIU.destination_longitude);
|
142
|
-
|
143
139
|
|
144
140
|
|
145
141
|
}catch(ClassNotFoundException e) {
|
@@ -182,13 +178,7 @@
|
|
182
178
|
|
183
179
|
public double current_longitude;//現在地 経度
|
184
180
|
|
185
|
-
|
181
|
+
|
186
|
-
|
187
|
-
public double destination_longitude;//目的地 経度
|
188
|
-
|
189
|
-
public String status;//選択肢
|
190
|
-
|
191
|
-
public String bodystatus;
|
192
182
|
|
193
183
|
|
194
184
|
|
@@ -206,59 +196,149 @@
|
|
206
196
|
|
207
197
|
}
|
208
198
|
|
209
|
-
|
199
|
+
}
|
200
|
+
|
210
|
-
|
201
|
+
```
|
202
|
+
|
203
|
+
###Clientプログラム(Android)
|
204
|
+
|
205
|
+
```Java
|
206
|
+
|
207
|
+
package com.websarva.wings.android.clientver3;
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
import androidx.appcompat.app.AppCompatActivity;
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
import android.os.Bundle;
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
import java.io.IOException;
|
220
|
+
|
221
|
+
import java.io.ObjectOutputStream;
|
222
|
+
|
223
|
+
import java.net.Socket;
|
224
|
+
|
225
|
+
import java.net.UnknownHostException;
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
public class MainActivity extends AppCompatActivity {
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
public static Socket socket = null;
|
234
|
+
|
235
|
+
public static String host = "192.168.11.2";
|
236
|
+
|
237
|
+
public static int port = 2001;
|
238
|
+
|
239
|
+
|
240
|
+
|
211
|
-
public
|
241
|
+
public static UserInformation cUI = new UserInformation ();
|
242
|
+
|
243
|
+
|
244
|
+
|
212
|
-
|
245
|
+
@Override
|
246
|
+
|
213
|
-
|
247
|
+
protected void onCreate(Bundle savedInstanceState) {
|
248
|
+
|
249
|
+
super.onCreate(savedInstanceState);
|
250
|
+
|
251
|
+
setContentView(R.layout.activity_main);
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
cUI.setcurrent_latitude(35.0);
|
256
|
+
|
257
|
+
cUI.setcurrent_longitude(139.0);
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
new Thread (new Runnable(){
|
264
|
+
|
265
|
+
public void run(){
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
ObjectOutputStream objectOutputStream = null;
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
try{
|
274
|
+
|
275
|
+
socket = new Socket(host,port);
|
276
|
+
|
277
|
+
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
objectOutputStream.writeObject(cUI);
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
objectOutputStream.close();
|
286
|
+
|
287
|
+
socket.close();
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
} catch (UnknownHostException e) {
|
292
|
+
|
293
|
+
e.printStackTrace();
|
294
|
+
|
295
|
+
} catch (IOException e) {
|
296
|
+
|
297
|
+
e.printStackTrace();
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
}).start();
|
214
306
|
|
215
307
|
}
|
216
308
|
|
217
|
-
|
218
|
-
|
219
|
-
public void setdestination_longitude(double inputdestination_longitude) {
|
220
|
-
|
221
|
-
this.destination_longitude = inputdestination_longitude;
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
public void setstatus(String inputstatus){
|
228
|
-
|
229
|
-
this.status =inputstatus;
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
public void setBodystatus(String inputbodystatus){
|
236
|
-
|
237
|
-
this.bodystatus =inputbodystatus;
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
309
|
}
|
244
310
|
|
245
311
|
```
|
246
312
|
|
313
|
+
###パーミッション
|
314
|
+
|
315
|
+
```xml
|
316
|
+
|
317
|
+
<manifest >
|
318
|
+
|
319
|
+
<uses-permission android:name="android.permission.INTERNET"/>
|
320
|
+
|
321
|
+
<application ~
|
322
|
+
|
323
|
+
</application>
|
324
|
+
|
325
|
+
</manifest>
|
326
|
+
|
327
|
+
```
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
#試したこと
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
Client(Android側)のプログラムを少しだけ変更しPC(Server)-PC(Client)で問題なく実行できていることを確認しています。そのときのPC(Client)プログラムが以下になります。
|
338
|
+
|
247
|
-
###Client
|
339
|
+
###ClientをPCにした場合
|
248
|
-
|
340
|
+
|
249
|
-
```
|
341
|
+
```java
|
250
|
-
|
251
|
-
package com.websarva.wings.android.clientver3;
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
import androidx.appcompat.app.AppCompatActivity;
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
import android.os.Bundle;
|
260
|
-
|
261
|
-
|
262
342
|
|
263
343
|
import java.io.IOException;
|
264
344
|
|
@@ -270,11 +350,9 @@
|
|
270
350
|
|
271
351
|
|
272
352
|
|
273
|
-
public class
|
353
|
+
public class Client_ver3 {
|
274
|
-
|
275
|
-
|
276
|
-
|
354
|
+
|
277
|
-
|
355
|
+
public static Socket socket = null;
|
278
356
|
|
279
357
|
public static String host = "192.168.11.2";
|
280
358
|
|
@@ -286,151 +364,15 @@
|
|
286
364
|
|
287
365
|
|
288
366
|
|
289
|
-
@Override
|
290
|
-
|
291
|
-
|
367
|
+
public static void main(String[] args) {
|
292
|
-
|
293
|
-
|
368
|
+
|
294
|
-
|
295
|
-
|
369
|
+
|
296
|
-
|
297
|
-
|
298
|
-
|
370
|
+
|
299
|
-
|
371
|
+
cUI.setcurrent_latitude(35.0);
|
300
372
|
|
301
373
|
cUI.setcurrent_longitude(139.0);
|
302
374
|
|
303
|
-
|
375
|
+
|
304
|
-
|
305
|
-
cUI.setdestination_longitude(139.5);
|
306
|
-
|
307
|
-
cUI.setstatus("gakusei");
|
308
|
-
|
309
|
-
cUI.setBodystatus("kennkou");
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
new Thread (new Runnable(){
|
314
|
-
|
315
|
-
public void run(){
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
ObjectOutputStream objectOutputStream = null;
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
try{
|
324
|
-
|
325
|
-
socket = new Socket(host,port);
|
326
|
-
|
327
|
-
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
objectOutputStream.writeObject(cUI);
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
objectOutputStream.close();
|
336
|
-
|
337
|
-
socket.close();
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
} catch (UnknownHostException e) {
|
342
|
-
|
343
|
-
e.printStackTrace();
|
344
|
-
|
345
|
-
} catch (IOException e) {
|
346
|
-
|
347
|
-
e.printStackTrace();
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
}
|
354
|
-
|
355
|
-
}).start();
|
356
|
-
|
357
|
-
}
|
358
|
-
|
359
|
-
}
|
360
|
-
|
361
|
-
```
|
362
|
-
|
363
|
-
###パーミッション
|
364
|
-
|
365
|
-
```xml
|
366
|
-
|
367
|
-
<manifest >
|
368
|
-
|
369
|
-
<uses-permission android:name="android.permission.INTERNET"/>
|
370
|
-
|
371
|
-
<application ~
|
372
|
-
|
373
|
-
</application>
|
374
|
-
|
375
|
-
</manifest>
|
376
|
-
|
377
|
-
```
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
#試したこと
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
Client(Android側)のプログラムを少しだけ変更しPC(Server)-PC(Client)で問題なく実行できていることを確認しています。そのときのPC(Client)プログラムが以下になります。
|
388
|
-
|
389
|
-
###ClientをPCにした場合
|
390
|
-
|
391
|
-
```java
|
392
|
-
|
393
|
-
import java.io.IOException;
|
394
|
-
|
395
|
-
import java.io.ObjectOutputStream;
|
396
|
-
|
397
|
-
import java.net.Socket;
|
398
|
-
|
399
|
-
import java.net.UnknownHostException;
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
public class Client_ver3 {
|
404
|
-
|
405
|
-
public static Socket socket = null;
|
406
|
-
|
407
|
-
public static String host = "192.168.11.2";
|
408
|
-
|
409
|
-
//public static String host = "127.0.0.1";
|
410
|
-
|
411
|
-
public static int port = 2001;
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
public static UserInformation cUI = new UserInformation ();
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
public static void main(String[] args) {
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
cUI.setcurrent_latitude(35.0);
|
424
|
-
|
425
|
-
cUI.setcurrent_longitude(139.0);
|
426
|
-
|
427
|
-
cUI.setdestination_latitude(35.5);
|
428
|
-
|
429
|
-
cUI.setdestination_longitude(139.5);
|
430
|
-
|
431
|
-
cUI.setstatus("gakusei");
|
432
|
-
|
433
|
-
cUI.setBodystatus("kennkou");
|
434
376
|
|
435
377
|
|
436
378
|
|
@@ -485,17 +427,3 @@
|
|
485
427
|
35.0
|
486
428
|
|
487
429
|
139.0
|
488
|
-
|
489
|
-
35.5
|
490
|
-
|
491
|
-
139.5
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
### 補足情報(FW/ツールのバージョンなど)
|
496
|
-
|
497
|
-
Server toughbook CF-20 ubuntu16.04LTS(PC)
|
498
|
-
|
499
|
-
Client GooglePixel4a Android12 (スマホ)
|
500
|
-
|
501
|
-
Client Surface Pro 7 Windows10(PC)
|
6
エラー文の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,6 +30,8 @@
|
|
30
30
|
|
31
31
|
```
|
32
32
|
|
33
|
+
java Server_ver3java.lang.ClassNotFoundException: com.websarva.wings.android.clientver3.UserInformation
|
34
|
+
|
33
35
|
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
|
34
36
|
|
35
37
|
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
|
5
ソースコードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -68,6 +68,10 @@
|
|
68
68
|
|
69
69
|
```Java
|
70
70
|
|
71
|
+
package com.websarva.wings.android.clientver3;
|
72
|
+
|
73
|
+
|
74
|
+
|
71
75
|
import java.io.IOException;
|
72
76
|
|
73
77
|
import java.io.ObjectInputStream;
|
@@ -160,6 +164,10 @@
|
|
160
164
|
|
161
165
|
```java
|
162
166
|
|
167
|
+
package com.websarva.wings.android.clientver3;
|
168
|
+
|
169
|
+
|
170
|
+
|
163
171
|
import java.io.Serializable;
|
164
172
|
|
165
173
|
|
@@ -238,6 +246,10 @@
|
|
238
246
|
|
239
247
|
```Java
|
240
248
|
|
249
|
+
package com.websarva.wings.android.clientver3;
|
250
|
+
|
251
|
+
|
252
|
+
|
241
253
|
import androidx.appcompat.app.AppCompatActivity;
|
242
254
|
|
243
255
|
|
4
ソースコード変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,11 +24,441 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
### 実行結果
|
27
|
+
### Server画面(PC) 実行結果
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
-
```
|
31
|
+
```
|
32
|
+
|
33
|
+
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
|
34
|
+
|
35
|
+
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
|
36
|
+
|
37
|
+
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
|
38
|
+
|
39
|
+
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
|
40
|
+
|
41
|
+
at java.lang.Class.forName0(Native Method)
|
42
|
+
|
43
|
+
at java.lang.Class.forName(Class.java:348)
|
44
|
+
|
45
|
+
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:720)
|
46
|
+
|
47
|
+
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1925)
|
48
|
+
|
49
|
+
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1808)
|
50
|
+
|
51
|
+
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2099)
|
52
|
+
|
53
|
+
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1625)
|
54
|
+
|
55
|
+
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:465)
|
56
|
+
|
57
|
+
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:423)
|
58
|
+
|
59
|
+
at Server_ver3.main(Server_ver3.java:24)
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
### 該当のソースコード
|
66
|
+
|
67
|
+
###Serverプログラム(PC)
|
68
|
+
|
69
|
+
```Java
|
70
|
+
|
71
|
+
import java.io.IOException;
|
72
|
+
|
73
|
+
import java.io.ObjectInputStream;
|
74
|
+
|
75
|
+
import java.net.ServerSocket;
|
76
|
+
|
77
|
+
import java.net.Socket;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
public class Server_ver3 {
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
public static ServerSocket serverSocket = null;
|
86
|
+
|
87
|
+
public static Socket socket =null;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
public static void main(String[] args) {
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
ObjectInputStream objectInputStream = null;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
try {
|
100
|
+
|
101
|
+
System.out.println("aaa");//デバッグのため
|
102
|
+
|
103
|
+
serverSocket = new ServerSocket(2001);
|
104
|
+
|
105
|
+
socket = serverSocket.accept();
|
106
|
+
|
107
|
+
System.out.println("bbb");//デバッグのため
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
objectInputStream = new ObjectInputStream(socket.getInputStream());
|
112
|
+
|
113
|
+
System.out.println("ccc");//デバッグのため
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
UserInformation cIU =(UserInformation)objectInputStream.readObject();//24行目
|
118
|
+
|
119
|
+
System.out.println("eee");//デバッグのため
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
objectInputStream.close();
|
124
|
+
|
125
|
+
serverSocket.close();
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
System.out.println(cIU.current_latitude);
|
130
|
+
|
131
|
+
System.out.println(cIU.current_longitude);
|
132
|
+
|
133
|
+
System.out.println(cIU.destination_latitude);
|
134
|
+
|
135
|
+
System.out.println(cIU.destination_longitude);
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
}catch(ClassNotFoundException e) {
|
140
|
+
|
141
|
+
e.printStackTrace();
|
142
|
+
|
143
|
+
}catch(IOException e) {
|
144
|
+
|
145
|
+
e.printStackTrace();
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
```
|
158
|
+
|
159
|
+
###UserInformationクラス(クラスオブジェクト)
|
160
|
+
|
161
|
+
```java
|
162
|
+
|
163
|
+
import java.io.Serializable;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
public class UserInformation implements Serializable {
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
public double current_latitude;//現在地 緯度
|
172
|
+
|
173
|
+
public double current_longitude;//現在地 経度
|
174
|
+
|
175
|
+
public double destination_latitude;//目的地 緯度
|
176
|
+
|
177
|
+
public double destination_longitude;//目的地 経度
|
178
|
+
|
179
|
+
public String status;//選択肢
|
180
|
+
|
181
|
+
public String bodystatus;
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
public void setcurrent_latitude(double inputcurrent_latitude) {
|
186
|
+
|
187
|
+
this.current_latitude = inputcurrent_latitude;
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
public void setcurrent_longitude(double inputcurrent_longitude) {
|
194
|
+
|
195
|
+
this.current_longitude = inputcurrent_longitude;
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
public void setdestination_latitude(double inputdestination_latitude) {
|
202
|
+
|
203
|
+
this.destination_latitude = inputdestination_latitude;
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
public void setdestination_longitude(double inputdestination_longitude) {
|
210
|
+
|
211
|
+
this.destination_longitude = inputdestination_longitude;
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
public void setstatus(String inputstatus){
|
218
|
+
|
219
|
+
this.status =inputstatus;
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
public void setBodystatus(String inputbodystatus){
|
226
|
+
|
227
|
+
this.bodystatus =inputbodystatus;
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
###Clientプログラム(Android)
|
238
|
+
|
239
|
+
```Java
|
240
|
+
|
241
|
+
import androidx.appcompat.app.AppCompatActivity;
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
import android.os.Bundle;
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
import java.io.IOException;
|
250
|
+
|
251
|
+
import java.io.ObjectOutputStream;
|
252
|
+
|
253
|
+
import java.net.Socket;
|
254
|
+
|
255
|
+
import java.net.UnknownHostException;
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
public class MainActivity extends AppCompatActivity {
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
public static Socket socket = null;
|
264
|
+
|
265
|
+
public static String host = "192.168.11.2";
|
266
|
+
|
267
|
+
public static int port = 2001;
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
public static UserInformation cUI = new UserInformation ();
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
@Override
|
276
|
+
|
277
|
+
protected void onCreate(Bundle savedInstanceState) {
|
278
|
+
|
279
|
+
super.onCreate(savedInstanceState);
|
280
|
+
|
281
|
+
setContentView(R.layout.activity_main);
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
cUI.setcurrent_latitude(35.0);
|
286
|
+
|
287
|
+
cUI.setcurrent_longitude(139.0);
|
288
|
+
|
289
|
+
cUI.setdestination_latitude(35.5);
|
290
|
+
|
291
|
+
cUI.setdestination_longitude(139.5);
|
292
|
+
|
293
|
+
cUI.setstatus("gakusei");
|
294
|
+
|
295
|
+
cUI.setBodystatus("kennkou");
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
new Thread (new Runnable(){
|
300
|
+
|
301
|
+
public void run(){
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
ObjectOutputStream objectOutputStream = null;
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
try{
|
310
|
+
|
311
|
+
socket = new Socket(host,port);
|
312
|
+
|
313
|
+
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
objectOutputStream.writeObject(cUI);
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
objectOutputStream.close();
|
322
|
+
|
323
|
+
socket.close();
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
} catch (UnknownHostException e) {
|
328
|
+
|
329
|
+
e.printStackTrace();
|
330
|
+
|
331
|
+
} catch (IOException e) {
|
332
|
+
|
333
|
+
e.printStackTrace();
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
}).start();
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
```
|
348
|
+
|
349
|
+
###パーミッション
|
350
|
+
|
351
|
+
```xml
|
352
|
+
|
353
|
+
<manifest >
|
354
|
+
|
355
|
+
<uses-permission android:name="android.permission.INTERNET"/>
|
356
|
+
|
357
|
+
<application ~
|
358
|
+
|
359
|
+
</application>
|
360
|
+
|
361
|
+
</manifest>
|
362
|
+
|
363
|
+
```
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
#試したこと
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
Client(Android側)のプログラムを少しだけ変更しPC(Server)-PC(Client)で問題なく実行できていることを確認しています。そのときのPC(Client)プログラムが以下になります。
|
374
|
+
|
375
|
+
###ClientをPCにした場合
|
376
|
+
|
377
|
+
```java
|
378
|
+
|
379
|
+
import java.io.IOException;
|
380
|
+
|
381
|
+
import java.io.ObjectOutputStream;
|
382
|
+
|
383
|
+
import java.net.Socket;
|
384
|
+
|
385
|
+
import java.net.UnknownHostException;
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
public class Client_ver3 {
|
390
|
+
|
391
|
+
public static Socket socket = null;
|
392
|
+
|
393
|
+
public static String host = "192.168.11.2";
|
394
|
+
|
395
|
+
//public static String host = "127.0.0.1";
|
396
|
+
|
397
|
+
public static int port = 2001;
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
public static UserInformation cUI = new UserInformation ();
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
public static void main(String[] args) {
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
cUI.setcurrent_latitude(35.0);
|
410
|
+
|
411
|
+
cUI.setcurrent_longitude(139.0);
|
412
|
+
|
413
|
+
cUI.setdestination_latitude(35.5);
|
414
|
+
|
415
|
+
cUI.setdestination_longitude(139.5);
|
416
|
+
|
417
|
+
cUI.setstatus("gakusei");
|
418
|
+
|
419
|
+
cUI.setBodystatus("kennkou");
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
ObjectOutputStream objectOutputStream = null;
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
try{
|
428
|
+
|
429
|
+
socket = new Socket(host,port);
|
430
|
+
|
431
|
+
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
objectOutputStream.writeObject(cUI);
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
objectOutputStream.close();
|
440
|
+
|
441
|
+
socket.close();
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
} catch (UnknownHostException e) {
|
446
|
+
|
447
|
+
e.printStackTrace();
|
448
|
+
|
449
|
+
} catch (IOException e) {
|
450
|
+
|
451
|
+
e.printStackTrace();
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
}
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
```
|
460
|
+
|
461
|
+
###実行結果(PCをClientにした際の結果)
|
32
462
|
|
33
463
|
aaa
|
34
464
|
|
@@ -36,416 +466,6 @@
|
|
36
466
|
|
37
467
|
ccc
|
38
468
|
|
39
|
-
ClassNotFoundException e
|
40
|
-
|
41
|
-
```
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
### 該当のソースコード
|
46
|
-
|
47
|
-
###Serverプログラム(PC)
|
48
|
-
|
49
|
-
```Java
|
50
|
-
|
51
|
-
import java.io.IOException;
|
52
|
-
|
53
|
-
import java.io.ObjectInputStream;
|
54
|
-
|
55
|
-
import java.net.ServerSocket;
|
56
|
-
|
57
|
-
import java.net.Socket;
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
public class Server_ver3 {
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
public static ServerSocket serverSocket = null;
|
66
|
-
|
67
|
-
public static Socket socket =null;
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
public static void main(String[] args) {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
ObjectInputStream objectInputStream = null;
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
try {
|
80
|
-
|
81
|
-
System.out.println("aaa");//デバッグのため
|
82
|
-
|
83
|
-
serverSocket = new ServerSocket(2001);
|
84
|
-
|
85
|
-
socket = serverSocket.accept();
|
86
|
-
|
87
|
-
System.out.println("bbb");//デバッグのため
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
objectInputStream = new ObjectInputStream(socket.getInputStream());
|
92
|
-
|
93
|
-
System.out.println("ccc");//デバッグのため
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
UserInformation cIU =(UserInformation)objectInputStream.readObject();//24行目
|
98
|
-
|
99
|
-
System.out.println("eee");//デバッグのため
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
objectInputStream.close();
|
104
|
-
|
105
|
-
serverSocket.close();
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
System.out.println(cIU.current_latitude);
|
110
|
-
|
111
|
-
System.out.println(cIU.current_longitude);
|
112
|
-
|
113
|
-
System.out.println(cIU.destination_latitude);
|
114
|
-
|
115
|
-
System.out.println(cIU.destination_longitude);
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
}catch(ClassNotFoundException e) {
|
120
|
-
|
121
|
-
System.out.println("ClassNotFoundException e");
|
122
|
-
|
123
|
-
}catch(IOException e) {
|
124
|
-
|
125
|
-
System.out.println("IOException e");
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
```
|
138
|
-
|
139
|
-
###UserInformationクラス(クラスオブジェクト)
|
140
|
-
|
141
|
-
```java
|
142
|
-
|
143
|
-
import java.io.Serializable;
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
public class UserInformation implements Serializable {
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
public double current_latitude;//現在地 緯度
|
152
|
-
|
153
|
-
public double current_longitude;//現在地 経度
|
154
|
-
|
155
|
-
public double destination_latitude;//目的地 緯度
|
156
|
-
|
157
|
-
public double destination_longitude;//目的地 経度
|
158
|
-
|
159
|
-
public String status;//選択肢
|
160
|
-
|
161
|
-
public String bodystatus;
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
public void setcurrent_latitude(double inputcurrent_latitude) {
|
166
|
-
|
167
|
-
this.current_latitude = inputcurrent_latitude;
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
public void setcurrent_longitude(double inputcurrent_longitude) {
|
174
|
-
|
175
|
-
this.current_longitude = inputcurrent_longitude;
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
public void setdestination_latitude(double inputdestination_latitude) {
|
182
|
-
|
183
|
-
this.destination_latitude = inputdestination_latitude;
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
public void setdestination_longitude(double inputdestination_longitude) {
|
190
|
-
|
191
|
-
this.destination_longitude = inputdestination_longitude;
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
public void setstatus(String inputstatus){
|
198
|
-
|
199
|
-
this.status =inputstatus;
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
public void setBodystatus(String inputbodystatus){
|
206
|
-
|
207
|
-
this.bodystatus =inputbodystatus;
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
}
|
214
|
-
|
215
|
-
```
|
216
|
-
|
217
|
-
###Clientプログラム(Android)
|
218
|
-
|
219
|
-
```Java
|
220
|
-
|
221
|
-
import androidx.appcompat.app.AppCompatActivity;
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
import android.os.Bundle;
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
import java.io.IOException;
|
230
|
-
|
231
|
-
import java.io.ObjectOutputStream;
|
232
|
-
|
233
|
-
import java.net.Socket;
|
234
|
-
|
235
|
-
import java.net.UnknownHostException;
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
public class MainActivity extends AppCompatActivity {
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
public static Socket socket = null;
|
244
|
-
|
245
|
-
public static String host = "192.168.11.2";
|
246
|
-
|
247
|
-
public static int port = 2001;
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
public static UserInformation cUI = new UserInformation ();
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
@Override
|
256
|
-
|
257
|
-
protected void onCreate(Bundle savedInstanceState) {
|
258
|
-
|
259
|
-
super.onCreate(savedInstanceState);
|
260
|
-
|
261
|
-
setContentView(R.layout.activity_main);
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
cUI.setcurrent_latitude(35.0);
|
266
|
-
|
267
|
-
cUI.setcurrent_longitude(139.0);
|
268
|
-
|
269
|
-
cUI.setdestination_latitude(35.5);
|
270
|
-
|
271
|
-
cUI.setdestination_longitude(139.5);
|
272
|
-
|
273
|
-
cUI.setstatus("gakusei");
|
274
|
-
|
275
|
-
cUI.setBodystatus("kennkou");
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
new Thread (new Runnable(){
|
280
|
-
|
281
|
-
public void run(){
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
ObjectOutputStream objectOutputStream = null;
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
try{
|
290
|
-
|
291
|
-
socket = new Socket(host,port);
|
292
|
-
|
293
|
-
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
objectOutputStream.writeObject(cUI);
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
objectOutputStream.close();
|
302
|
-
|
303
|
-
socket.close();
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
} catch (UnknownHostException e) {
|
308
|
-
|
309
|
-
e.printStackTrace();
|
310
|
-
|
311
|
-
} catch (IOException e) {
|
312
|
-
|
313
|
-
e.printStackTrace();
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
}).start();
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
}
|
326
|
-
|
327
|
-
```
|
328
|
-
|
329
|
-
###パーミッション
|
330
|
-
|
331
|
-
```xml
|
332
|
-
|
333
|
-
<manifest >
|
334
|
-
|
335
|
-
<uses-permission android:name="android.permission.INTERNET"/>
|
336
|
-
|
337
|
-
<application ~
|
338
|
-
|
339
|
-
</application>
|
340
|
-
|
341
|
-
</manifest>
|
342
|
-
|
343
|
-
```
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
#試したこと
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
Client(Android側)のプログラムを少しだけ変更しPC(Server)-PC(Client)で問題なく実行できていることを確認しています。そのときのPC(Client)プログラムが以下になります。
|
354
|
-
|
355
|
-
###ClientをPCにした場合
|
356
|
-
|
357
|
-
```java
|
358
|
-
|
359
|
-
import java.io.IOException;
|
360
|
-
|
361
|
-
import java.io.ObjectOutputStream;
|
362
|
-
|
363
|
-
import java.net.Socket;
|
364
|
-
|
365
|
-
import java.net.UnknownHostException;
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
public class Client_ver3 {
|
370
|
-
|
371
|
-
public static Socket socket = null;
|
372
|
-
|
373
|
-
public static String host = "192.168.11.2";
|
374
|
-
|
375
|
-
//public static String host = "127.0.0.1";
|
376
|
-
|
377
|
-
public static int port = 2001;
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
public static UserInformation cUI = new UserInformation ();
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
public static void main(String[] args) {
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
cUI.setcurrent_latitude(35.0);
|
390
|
-
|
391
|
-
cUI.setcurrent_longitude(139.0);
|
392
|
-
|
393
|
-
cUI.setdestination_latitude(35.5);
|
394
|
-
|
395
|
-
cUI.setdestination_longitude(139.5);
|
396
|
-
|
397
|
-
cUI.setstatus("gakusei");
|
398
|
-
|
399
|
-
cUI.setBodystatus("kennkou");
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
ObjectOutputStream objectOutputStream = null;
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
try{
|
408
|
-
|
409
|
-
socket = new Socket(host,port);
|
410
|
-
|
411
|
-
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
objectOutputStream.writeObject(cUI);
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
objectOutputStream.close();
|
420
|
-
|
421
|
-
socket.close();
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
} catch (UnknownHostException e) {
|
426
|
-
|
427
|
-
e.printStackTrace();
|
428
|
-
|
429
|
-
} catch (IOException e) {
|
430
|
-
|
431
|
-
e.printStackTrace();
|
432
|
-
|
433
|
-
}
|
434
|
-
|
435
|
-
}
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
```
|
440
|
-
|
441
|
-
###実行結果(PCをClientにした際の結果)
|
442
|
-
|
443
|
-
aaa
|
444
|
-
|
445
|
-
bbb
|
446
|
-
|
447
|
-
ccc
|
448
|
-
|
449
469
|
eee
|
450
470
|
|
451
471
|
35.0
|
3
題名の変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
ソケット通信においてPC-Android間の通信ができない
|
test
CHANGED
File without changes
|
2
説明の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -326,6 +326,8 @@
|
|
326
326
|
|
327
327
|
```
|
328
328
|
|
329
|
+
###パーミッション
|
330
|
+
|
329
331
|
```xml
|
330
332
|
|
331
333
|
<manifest >
|
1
プレビューの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
###
|
1
|
+
### PC-Android間の通信を実現したい
|
2
2
|
|
3
3
|
TCPを使用したソケット通信にてクラスオブジェクトを送受信したいです。
|
4
4
|
|