자바로 서버를 구축하려고합니다. WindowBuilder를 사용하고있는데요,
사용하고있지 않은 포트에서 소켓통신을 하려고 하는데도 계속 소켓통신이 되지를 않습니다.
아래는 소스첨부입니다.
--ServerUI.java
package graduate.server;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
public class ServerUI {
private JFrame frame;
private JLabel label_1;
ServerClass serverClass = new ServerClass();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ServerUI window = new ServerUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public ServerUI() {
initialize();
try
{
serverClass.setPort(8009);
serverClass.startServer();
}
catch (Exception e)
{
// TODO: handle exception
}
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
label_1 = new JLabel("New label");
frame.getContentPane().add(label_1, BorderLayout.NORTH);
/*if(serverClass.ifServeropend() == true)
{
label_1.setText("되요");
}
else
{
label_1.setText("안되요");
}*/
}
}
--ServerClass.java
package graduate.server;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerClass {
private int port;
public boolean server_State = false;
public ServerSocket s_Socket;
public Socket socket;
public void setPort(int set_port)
{
this.port = set_port;
}
public void startServer()
{
try
{
s_Socket = new ServerSocket(port);
socket = s_Socket.accept();
if(socket.isConnected() == true)
{
server_State = true;
}
}
catch (Exception e)
{
// TODO: handle exception
}
}
public boolean ifServeropend()
{
return server_State;
}
}
위처럼 serverclass.java를 상속받아서 하는데 오류가 뜨더군요;
serverclass.java를 상속받지않고 serverui.java에서 날코딩으로 하여도 소켓통신이 되질 않습니다.
무슨문제일까요...