1
학생이 이름, ID, 전자 메일, 전화 번호를 입력 한 다음 저장 버튼을 클릭해야 응용 프로그램을 프로그래밍하고 싶습니다. 서버에 보내고 file.txt로 저장 ,,,,이 코드를 작성했지만이 오류는 "java.net.ConnectException : Connection refused : connect"클라이언트 측에서 이 코드를 실행하면 실행됩니다. 제발 도와주세요 ??java.net.ConnectException : 연결이 거부되었습니다 : 클라이언트/서버 TCP 소켓에 오류가 발생했습니다.
서버 :
package server;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static void main(String[] args) {
try {
ServerSocket service;
service = new ServerSocket(1309);
Socket server = service.accept();
System.out.println("server has connected");
InputStreamReader input = new InputStreamReader(server.getInputStream());
DataOutputStream output = new DataOutputStream(server.getOutputStream());
BufferedReader in = new BufferedReader(input);
String inpput = in.readLine();
PrintWriter f = new PrintWriter("student.txt", "UTF-8");
f.println(inpput);
f.close();
service.close();
} catch (IOException e) {
System.out.println(e);
}
}
private static FileWriter FileWriter(String studenttxt) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
클라이언트 :
package project4;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
public class p4 extends javax.swing.JFrame {
public p4() {
initComponents();}
private void saveActionPerformed(java.awt.event.ActionEvent evt) {
try {
Socket client = new Socket("localhost", 1309);
InputStreamReader input = new InputStreamReader(client.getInputStream());
DataOutputStream output = new DataOutputStream(client.getOutputStream());
BufferedReader in = new BufferedReader(input);
String n, i, e, t;
n = name.getText();
i = id.getText();
e = email.getText();
t = phone.getText();
String mm = n + i + e + t;
output.writeBytes(mm);
output.flush();
System.out.println("save");
output.close();
input.close();
client.close();
} catch (IOException o) {
System.out.println(o);
}}
public static void main(String args[]) {
p4 n = new p4();
n.saveActionPerformed(null);
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new p4().setVisible(true);
}
});
}
public javax.swing.JTextField email;
public javax.swing.JTextField id;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
public javax.swing.JTextField name;
public javax.swing.JTextField phone;
protected javax.swing.JButton save; }
예, 방화벽을 종료하고 작동하지 않습니다.하지만 클라이언트에서 파일을 실행할 때 버튼을 클릭하기 전에 구현됩니다. 이유를 모르겠 음 ..... – ala