YEAAAAAAHHHHH

This commit is contained in:
Lorenzo Iovino 2017-07-07 01:12:25 +02:00
parent 09ced44428
commit ada17053d8
8 changed files with 1013 additions and 175 deletions

View file

@ -8,6 +8,8 @@ import models.Message;
import javax.swing.*;
import java.io.IOException;
import java.net.*;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
/**
* Created by loke on 29/06/2017.
@ -29,17 +31,31 @@ public class SendWords extends SwingWorker<Void,Void> {
public Void doInBackground() {
DatagramSocket clientSocket = null;
try {
clientSocket = new DatagramSocket();
InetAddress hostIP = InetAddress.getLocalHost();
InetSocketAddress myAddress =
new InetSocketAddress(hostIP, Config.WordsReceiverServerPort);
DatagramChannel datagramChannel = DatagramChannel.open();
datagramChannel.bind(null);
ByteBuffer buffer = ByteBuffer.allocate(1024);
Message msg = new Message("WORDS", App.session.account.userName, "", words);
String sentence = msg.toString();
buffer.put(sentence.getBytes());
buffer.flip();
datagramChannel.send(buffer, myAddress);
buffer.clear();
/*clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName(Config.WordsReceiverServerURI);
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
Message msg = new Message("WORDS", App.session.account.userName, "", words);
String sentence = msg.toString();
sendData = sentence.getBytes();
System.out.println("SENDIJIIDIIDIDIDIDDIDIDIDIDI");
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Config.WordsReceiverServerPort);
clientSocket.send(sendPacket);
//clientSocket.close();
clientSocket.close();*/
return null;
} catch (UnknownHostException e) {

View file

@ -43,7 +43,7 @@ public class WaitForScore extends SwingWorker<Void,Void> {
System.out.println("HSHSHSHS");
System.out.println(s);
msg = Message.toMessage(s);
if(msg.message.equals("ASD")){
if(msg.message.equals("FINALSCORE")){
break;
}
}