network interface

This commit is contained in:
hba56
2017-08-30 12:13:17 +12:00
parent ca0a3f2a8b
commit b2bd4fdc1c
7 changed files with 66 additions and 16 deletions
+5
View File
@@ -1,7 +1,12 @@
package app;
import networkInterface.NetworkInterface;
/**
* Used when starting the matchmaking browser
*/
public class Main {
public static void main(String[] args) {
NetworkInterface networkInterface = new NetworkInterface();
}
}
@@ -1,17 +1,23 @@
package networkInterface;
import java.io.*;
import java.net.*;
import network.Exceptions.InvalidMessageException;
import network.MessageDecoders.HostedGamesRequestDecoder;
import network.Messages.HostGamesRequest;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
/**
* Holds the output for the network for
*/
public class InInterface {
public class NetworkInterface {
private DatagramSocket serverSocket;
private byte[] receiveData = new byte[1024];
private byte[] sendData = new byte[1024];
public InInterface(){
public NetworkInterface(){
try {
this.serverSocket = new DatagramSocket(3779);
@@ -29,6 +35,14 @@ public class InInterface {
serverSocket.receive(receivePacket);
//decode and update table
HostedGamesRequestDecoder decoder = new HostedGamesRequestDecoder();
HostGamesRequest newKnownGames;
try{
newKnownGames = (HostGamesRequest) decoder.decode(receivePacket.getData());
System.out.println(newKnownGames.getKnownGames().get(0));
}catch (InvalidMessageException e){
System.err.println("Message received that is not a hostedGamesRequest packet");
}
//client ip and port
InetAddress IPAddress = receivePacket.getAddress();
@@ -36,6 +50,7 @@ public class InInterface {
// String capitalizedSentence = sentence.toUpperCase();
// sendData = capitalizedSentence.getBytes();
// DatagramPacket sendPacket =
@@ -1,7 +0,0 @@
package networkInterface;
/**
* Holds the connection to the network for output
*/
public class OutInterface {
}