1 Replies - 1165 Views - Last Post: 11 November 2009 - 10:00 PM Rate Topic: -----

#1 jonnyboy12   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-November 09

adding swing to a simple server

Posted 11 November 2009 - 09:54 PM

Hello i am currently working on a small client/ server. They are both fully operational although i am having trouble adding swing to it. I Just posted the server for now minus the imports. My goal is to build a basic interface to display the ObjectInput and Output streams in mabey a formatted textfield. Any tips on where to begin would be a big help.





public class ServerSocketExample2
{

private ServerSocket server;

private int port = 8888;



public ServerSocketExample2 () {


try {

server = new ServerSocket(port);

} catch (IOException e) {

e.printStackTrace();

}

}

public static void main(String[] args) {
// Stream to write file



ServerSocketExample2 example = new ServerSocketExample2();

example.handleConnection();




}

public void handleConnection() {

System.out.println("Waiting for client message...");

//

// The server do a loop here to accept all connection initiated by the

// client application.

//

while (true) {

try {

Socket socket = server.accept();

new ConnectionHandler(socket);

} catch (IOException e) {

e.printStackTrace();

}

}

}


class ConnectionHandler {

private Socket socket;


public ConnectionHandler(Socket socket) {

try

{

// Read a message sent by client application

ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());

String message = (String) ois.readObject();

System.out.println("Message Received: " + message);

ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());

oos.writeObject("Hi...");




ois.close();

oos.close();

socket.close();


} catch (IOException e) {

e.printStackTrace();

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

}}}

Is This A Good Question/Topic? 0
  • +

Replies To: adding swing to a simple server

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: adding swing to a simple server

Posted 11 November 2009 - 10:00 PM

Welcome at DIC
Please respect rule #4 of this forum that was showed to you when you posted
:code:

Don't see any GUI (Swing) in your code
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1