我在2个JFrame之间创建了一个简单的聊天系统,当单独运行每个JFrame时,一切正常,但是要将值从JF1传递到JF2,使用此方法:
try {
showClient();
ss=new ServerSocket(1201);// server port
s=ss.accept();// accept conx
din=new DataInputStream(s.getInputStream());
dout=new DataOutputStream(s.getOutputStream());
while(!msgin.equals("exit")){
msgin=din.readUTF();
msg_area.setText(msg_area.getText().trim()+"\n User 2: "+msgin); //send msg
}
}catch(Exception e){
System.out.println("Error" + e);
}
我从主方法中调用它:
public static void startServer(){
try{
s =new Socket("127.0.0.1",1201);// local ip address of user 2
din=new DataInputStream(s.getInputStream());
dout=new DataOutputStream(s.getOutputStream());
String msgin="";
while(!msgin.equals("exit")){
msgin=din.readUTF();
msg_area.setText(msg_area.getText().trim()+"\n User 1: "+msgin);
}
}catch(Exception e){
System.out.println("Error" + e);
}
}
另一方面,这是被调用的方法:
version : '2'
services:
nginx:
image: tutum/nginx
ports:
- "80:80"
volumes:
- ./nginx/default:/etc/nginx/sites-available/default
- ./nginx/default:/etc/nginx/sites-enabled/default
- ./logs/nginx-error.log:/var/log/nginx/error.log
- ./logs/nginx-access.log:/var/log/nginx/access.log
- ./app:/usr/share/nginx/html
phpfpm:
image: php:fpm
ports:
- 9000:9000
volumes:
- ./app:/usr/share/nginx/html
composer:
image: composer/composer:php7
command: install
volumes:
- ./app:/app
elastic2.4.4:
image: elasticsearch:2.4.4
ports:
- 9200:9200
volumes:
- ./esdata1:/usr/share/elasticsearch/data
redis:
image: redis:3.2
ports:
- 6379:6379
错误是" java.net.ConnectException:连接被拒绝"。
注意:单独运行每个类时,我调用相同的方法(startServer())并建立连接。