Please don't assume that people follow your issue from thread to thread. Folks (myself included) don't have any way of knowing what you're talking about. You will get better, faster help by confining related issues to the same thread. If you do start a new thread, at the very least, thoroughly describe the issue or provide a link to the previous thread.
Below works perfectly:
import java.net.*;
import java.util.*;
import java.io.*;
public class Server{
Set strings;
ServerSocket server;
Socket connection;
ObjectInputStream input;
Iterator it;
public static void main(String args[]){
Server server;
server = new Server();
server.init();
}
public void init(){
try{
server = new ServerSocket(5000);
connection = server.accept();
input = new ObjectInputStream(connection.getInputStream());
strings = (Set) input.readObject();
System.out.println("Recived Set, Objects In Set = " + strings.size());
}
catch(Exception e){System.out.println(e);}
}
}
import java.net.*;
import java.util.*;
import java.io.*;
public class Client{
Set strings;
ServerSocket server;
Socket connection;
ObjectOutputStream output;
Bullet b1;
Bullet b2;
Iterator it;
public static void main(String args[]){
Client client;
client = new Client();
client.init();
}
public void init(){
try{
b1 = new Bullet();
b2 = new Bullet();
strings = new HashSet();
strings.add(b1);
strings.add(b2);
connection = new Socket(InetAddress.getLocalHost(), 5000);
output = new ObjectOutputStream(connection.getOutputStream());
output.writeObject(strings);
System.out.println("Size of strings = " + strings.size());
}
catch(Exception e){System.out.println(e);}
}
}
Why doesnt the next block of code work:
public void updatePosition(int x, int y, Set b){
try{
output.writeInt(x);
output.writeInt(y);
output.writeObject(b);
System.out.println(b.size());
output.flush();
}catch(Exception e){System.out.println(e);}
}
public void run(){
try{
alive = true;
output.writeObject("Connection Complete");
while(alive){
x = (int)input.readInt();
y = (int)input.readInt();
bullets = (Set)input.readObject();
System.out.println(bullets.size());
it = bullets.iterator();
while(it.hasNext()){
temp = (Bullet)it.next();
System.out.println("Bullets");
}
main.updateAll(x, y, playerNumber, bullets);
}
}catch(Exception e){System.out.println(e);}
}
On the client side it gets the size correct, but on the server side it recieves the set with no values, the size is 0. Why?
Thatsd the original q