finished ChatClient for partII

git-svn-id: svn://anubis/gvsu@20 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-02-17 23:05:27 +00:00
parent 10bf3e096d
commit 6d10aff0fa

View File

@ -36,7 +36,8 @@ public class ChatClient {
byte[] buffer = new byte[1000];
DatagramPacket datagram = new DatagramPacket(buffer, buffer.length);
socket.receive(datagram);
String message = new String(datagram.getData());
String message = new String(datagram.getData(), 0,
datagram.getLength());
gui.output.append(message);
}
} catch (IOException e) {
@ -45,9 +46,16 @@ public class ChatClient {
}
public void sendTextToChat(String message) {
if (message.equals("Bye"))
{
socket.close();
System.exit(0);
return;
}
message = name+": "+message+"\n";
byte[] buf = (message).getBytes();
DatagramPacket dg = new DatagramPacket(buf, buf.length);
DatagramPacket dg = new DatagramPacket(buf, buf.length,
group, port);
try {
socket.send(dg);
}