So, I'm programming a UDP Server-Client app, but here's the problem:
a) a client conects, and sends the message "conectar#Username" , being Username a getText from a field.
This is ok. Sample 'conectar#Manchester'
b) the server receives it, and ok, everything is fine.
c) if another client try to connect, and it's username is smaller than the previous ones, everything goes wrong...
Sample: 'conectar#Chelsea', becomes 'conectar#Chelseater'
It keeps getting the size of the first one... How can I fix that???
Here's the basic code of the receive and send stuff:
Server:
while (true) {
try {
DatagramPacket packet = new DatagramPacket(receiveData, receiveData.length);
socket.receive(packet);
String sentence = new String(packet.getData());
Clients:
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("127.0.0.1");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
sentence = ("conectar#" + TFUser.getText());
sendData = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 5555);
clientSocket.send(sendPacket);
Anyone can help? Thanks...