java - integer wont send over a socket and is received as a String by client -
i'm trying create client/server chat room program , each client gui needs display list of active users sent server. need send number of users in list client. when try sent int on socket throws type mismatch error. more point if try , send string , parse int random alphanumeric string appears out of nowhere. know variable sending integer number though don't understand what's going on. i've left in different solutions comments too. server:
public void updateclientuserlist() { //int userlistsize = userlist.size(); output.print((int)userlist.size()); for(int = 0; < userlist.size(); ++i) { string user; user = userlist.get(i).getusername(); output.println(user); } chatlog.add("new user(s) has joined chatroom"); }
client:
public static void updateuserlist() { string users = ""; //string numinput = input.next(); int userlistsize = input.nextint();//integer.parseint(numinput); //for(int = 0; < userlistsize; ++i) //{ // string user = input.nextline(); // userlist.add(i, user); //} //users = userlist.get(0); for(int = 0; < userlistsize; ++i) { users += input.nextline(); } userlistbox.settext(users); }
to pass int need dataoutputstream ; u call writeint this
sockdataout = new dataoutputstream(socket.getoutputstream()); sockdataout.writeint(11);
and in client side u do:
sockdatain = new datainputstream(socket.getinputstream()); sockdatain.readint();
Comments
Post a Comment