|
public class NetworkActionServer extends Thread {
private static final int serverport = 8899;
Ranch
private Socket serversocket;
DBAction db = new DBAction ();
Ranch
NetworkActionServer (Socket i) {
this.serversocket = i;
}
Ranch
// Get the message from C and return the verification message
public void run () {
try {
Ranch
// get client mes
ObjectInputStream InputStream = new ObjectInputStream (serversocket.getInputStream ());
User usr = (User) InputStream.readObject ();
// do client mes
db.insertInto (usr);
// Return verification message
ObjectOutputStream OutputStream = new ObjectOutputStream (serversocket.getOutputStream ());
User [] dbusr = db.selectall ();
for (int i = 0; i <dbusr.length; i ++) {
System.out.println (dbusr [i] .getName ());
OutputStream.writeObject ("a"); /////////////
////////////////////////// Cannot write objects here, socket write error
//Thread.sleep(3000);
}
OutputStream.flush ();
} catch (Exception e) {
e.printStackTrace ();
}
}
Ranch
public static void main (String arg []) {
try {
ServerSocket servercon = new ServerSocket (serverport);
while (true) {
Socket s = servercon.accept ();
Thread t = new NetworkActionServer (s);
t.start ();
}
} catch (Exception e) {
e.printStackTrace ();
}
Ranch
}
}
Just
socket write error ..... everyone help, thank you |
|