Looking for some help on a Client Server program for class. I am stuck on an error that says "java.lang.Integer cannot be cast to client1.Client$Employee". Not for sure what this is and have spent several hours working on it and trying different things. Anyone have any ideas?
That's a lot of code; it would sure help if you'd give us all the information the compiler is giving you -- i.e., the line number where the error occurs!
But in general terms, it looks like you're using serialization to send objects between a client and server process over a socket. I see Strings, Integers, and Employee objects being written, and I see places in the code where you're reading an object and expecting it to be an Integer, a String, or an Employee, at different points. In any case, the error just means -- and I think you probably know this -- that at one of the points where you're expecting an Integer, the object you're getting over the socket is actually an Employee. All I can tell you is that you need to go over the logic, carefully, and make sure you understand the conditions under which each kind of object can be transmitted; and make sure that the other end always has a way to know what's coming next.
The server logs some messages for every request it processes. When you run this, and have an error with the FIND command, do you see FIND-related messaages on the server? What do they say?
The problem is that when your Server first connects to a client, it sends an Integer as a handshake, and your Client never reads that Integer. So later, when you do a FIND, then read the input stream you get the Integer that has been sitting there in the buffer waiting to be taken.
You should read the integer immediately after making the connection to the Server:
Steve
Good heavens! What have you done! Here, try to fix it with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss