finished ChatClient for partII
git-svn-id: svn://anubis/gvsu@20 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
10bf3e096d
commit
6d10aff0fa
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user