質問するログイン新規登録

質問編集履歴

1

コードを追加しました

2017/01/13 09:30

投稿

luna12
luna12

スコア47

title CHANGED
File without changes
body CHANGED
@@ -26,7 +26,7 @@
26
26
  at adaputa_dummy.dummy.main(dummy.java:53)
27
27
  ```
28
28
 
29
- ###該当のソースコード
29
+ ###クライアントプログラム
30
30
  ```java
31
31
  //dummy.java
32
32
  String server = "localhost";
@@ -42,6 +42,58 @@
42
42
  //以下略
43
43
  ```
44
44
 
45
+ ###サーバープログラム
46
+ ```
47
+ /**
48
+ * コンストラクタ
49
+ * @throws IOException
50
+ */
51
+ public TransDummy() throws IOException {
52
+ String file="./conf/conf.properties";
53
+ conf = new Properties();
54
+ conf.load(new FileInputStream(file));
55
+
56
+ ss = new ServerSocket(Integer.parseInt(conf.getProperty("trans_port")));
57
+
58
+ //接続待ち
59
+ for(;;){
60
+ connect();
61
+ }
62
+ }
63
+
64
+ /**
65
+ * との接続を行う
66
+ * @throws IOException
67
+ */
68
+ private void connect() throws IOException{
69
+ logger.info("Connection開始");
70
+ //ここでとまって接続待ち状態になります
71
+ ★s = ss.accept();
72
+ InputStream is = s.getInputStream();
73
+ DataInputStream input = new DataInputStream(is);
74
+ byte[] msg = new byte[12];
75
+ input.read(msg, 0, 12);
76
+
77
+ //受信メッセージ内容確認
78
+ System.out.println("受信メッセージ内容:");
79
+ for(int i = 0; i< msg.length; i++){
80
+ System.out.print(Integer.toHexString(msg[i] & 0xff) + " ");
81
+ }
82
+ System.out.println();
83
+
84
+ //受信メッセージの長さだけチェック
85
+ if(msg.length == 12){
86
+ //メッセージを受信した場合の処理です
87
+ response(Integer.parseInt(conf.getProperty("trans_response")), msg);
88
+ } else{
89
+ logger.warning("受信データエラー");
90
+ System.exit(1);
91
+ }
92
+
93
+ logger.info("Connection終了");
94
+ }
95
+ ```
96
+
45
97
  ###試したこと
46
98
  色々通信の設定を変えて試してみたり、
47
99
  他にはコンパネ→システムとセキュリティ→Windowsファイアウォールによるアプリケーションの許可→リモートデスクトップの許可にチェックをいれてみたり。。(ポートの解放?)