Skip to content
Snippets Groups Projects
Commit 5806c893 authored by Thea Olivia's avatar Thea Olivia
Browse files

Server.java and Paxos.java update

parent 70d3442c
No related merge requests found
...@@ -9,5 +9,16 @@ import org.json.simple.parser.JSONParser; ...@@ -9,5 +9,16 @@ import org.json.simple.parser.JSONParser;
public class Paxos public class Paxos
{ {
DatagramSocket clientSocket;
public void sendRequest(String sentence, String host, int port)
{
clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress();
byte[] sendData = new byte[1024];
System.out.println(sentence);
sendData = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket();
clientSocket.send(sendPacket);
}
} }
\ No newline at end of file
...@@ -6,15 +6,22 @@ import java.net.ConnectException; ...@@ -6,15 +6,22 @@ import java.net.ConnectException;
import java.net.NoRouteToHostException; import java.net.NoRouteToHostException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.json.simple.JSONArray; import org.json.JSONArray;
import org.json.simple.JSONObject; import org.json.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.parser.JSONParser;
public class Server public class Server
{ {
private String host;
private int port;
private Socket socket;
private final String DEFAULT_HOST = "localhost";
public Server() public Server()
{ {
this.host = host;
this.port = port;
this.socket = socket;
} }
public boolean isWerewolf() public boolean isWerewolf()
...@@ -23,11 +30,9 @@ public class Server ...@@ -23,11 +30,9 @@ public class Server
return yes; return yes;
} }
public void connect(String host, int port) throws IOException public void connect(String host, int port) throws IOException
{ {
this.host = hostl this.host = host;
this.port = port; this.port = port;
socket = new Socket(host, port); socket = new Socket(host, port);
System.out.println("Game sudah dimulai... V^__^V"); System.out.println("Game sudah dimulai... V^__^V");
...@@ -36,7 +41,27 @@ public class Server ...@@ -36,7 +41,27 @@ public class Server
public JSONObject receiveJSON() throws IOException public JSONObject receiveJSON() throws IOException
{ {
InputStream in = socket.getInputStream();
ObjectInputStream i = new ObjectInputStream();
JSONObject line = null;
try {
line = (JSONObject) i.readObject();
} catch (ClassNotFoundException e){
e.printStackTrace();
}
return line;
}
public void sendJSON(JSONObject jsonObj) throws IOException
{
JSONObject jsonObject2 = new JSONObject();
jsonObject2.put("key", new Paper(250,333));
OutputStream out = socket.getOutputStream();
ObjectOutputStream o = new ObjectOutputStream(out);
o.writeObject(jsonObject2);
out.flush();
} }
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment