I cannot get this socket to work:
Do i need to import a library or is it wrong in the code? running netbeans /ThanksCode:/*
* ServerClassApp.java
*/
package serverclass;
import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
/**
* The main class of the application.
*/
public class ServerClassApp extends SingleFrameApplication {
private static void listenSocket() {
throw new UnsupportedOperationException("Not yet implemented");
}
/**
* At startup create and show the main frame of the application.
*/
@Override protected void startup() {
show(new ServerClassView(this));
}
/**
* This method is to initialize the specified window by injecting resources.
* Windows shown in our application come fully initialized from the GUI
* builder, so this additional configuration is not needed.
*/
@Override protected void configureWindow(java.awt.Window root) {
}
/**
* A convenient static getter for the application instance.
* @return the instance of ServerClassApp
*/
public static ServerClassApp getApplication() {
return Application.getInstance(ServerClassApp.class);
}
/**
* Main method launching the application.
*/
public static void main(String[] args) {
launch(ServerClassApp.class, args);
/**
* Using socket to select what port the server will be listening to, and if not possible, print a message.
*/
Public viod listenSocket(){
try{
server = new ServerSocket (4111);
}
catch (IOExeption e){
System.out.println("Can't listen to port nr 4111");
System.exit(-1);
}
/**
* Creates the connection between client and server class *smiley*
*/
try{
client = server.accept();
} catch (IOExeption e) {
System.out.println("Could not establish connection on port 4111");
System.exit(-1);
/**
* Reads the data from client
*/
}
try {
in = new BufferedReader (new InputSteamReader (
client.getInputStrem()));
out = new PrintWriter(client.getInputStream(),
true);
} catch (IOExpection e) {
System.out.println("Could not read message.");
System.exit(-1);
}
/**
* Loops the input stream and echo
*/
while(true) {
try{
line = in.readLine();
out.println(line);
} catch (IOException e) {
System.out.println("Can't read input stream data");
System.exit(-1);
}
}
}
public void actionPreformed(ActionEvent event) {
Object source = event.getSource();
If(source == button){
textArea.setText(line);
}
}
}
}
}
}

