i am slowly learning to code as an evening course. We have an assignment to code a client application that takes an input string, splits into two halves and assigns them to packets. These are sent to a server application that then takes the two halves, swaps them round and sends them back to front to the client. The client then prints the results and confirms if the string returned matches the input string. I have coded this and it kind of works. I am stuck on one thing. For some reason my byte arrays are not resetting after a message is sent from the server and what ends up happening is that it returns the characters from a new string and if this new string is shorter than old string the remaining characters are also returned. What have i done wrong here? I suspect it might be cos i have set the byte array on the server to 128 bits so just carries on till it runs out of memory? If that is case i dont know how to assign a length to the array based on the incoming packet as i declare the array before the packet arrives! Any advice would be great or indeed a topic i need to revisit in my studies that could explain the issue!
This is the client code:
This is the server code: