Skip to content
Snippets Groups Projects
Commit c71ea6ed authored by jrb240's avatar jrb240
Browse files

Server receiving for reviews and users completed. Events receiving is blank....

Server receiving for reviews and users completed. Events receiving is blank. Reviews had to be changed so that sorting can be done for app side.
parent db61cd5f
No related branches found
No related tags found
1 merge request!25Server receiving for reviews and users completed. Events receiving is blank....
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class EventRecieveThread implements Runnable{
Model usingModel;
EventRecieveThread(Model newModel){
usingModel = newModel;
}
@Override
public void run() {
int portNumber = 8002;
while (true) {
try(ServerSocket userServer = new ServerSocket(portNumber);
Socket clientSocket = userServer.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()))
) {
System.out.println("got connection to add Event");
} catch (IOException e) {
continue;
}
}
}
}
......@@ -12,9 +12,20 @@ public class Main {
address = Inet4Address.getLocalHost().getHostAddress();
System.out.println(address);
//tell everyone about eachother
Model model = new Model();
UserReThread userReceiving = new UserReThread();
UserReThread userReceiving = new UserReThread(model);
EventRecieveThread eventReceiving = new EventRecieveThread(model);
ReviewRecieveThread reviewReceiving = new ReviewRecieveThread(model);
//turn them into threads
Thread userReceivingThread = new Thread(userReceiving);
Thread eventReceivingThread = new Thread(eventReceiving);
Thread reviewReceivingThread = new Thread(reviewReceiving);
//start these threads
userReceivingThread.start();
eventReceivingThread.start();
reviewReceivingThread.start();
}
}
\ No newline at end of file
......@@ -11,10 +11,11 @@ public class Model {
reviews = new ArrayList<>();
events = new ArrayList<>();
}
public static void addUser(ServerUser newUser) {
public void addUser(ServerUser newUser) {
users.add(newUser);
System.out.println("added user");
}
public void addReview(Review newReview){
reviews.add(newReview);
System.out.println("added review");
......@@ -23,4 +24,12 @@ public class Model {
events.add(newEvent);
System.out.println("added event");
}
public boolean usersContains(String user,String password){
for (ServerUser u : users){
if (u.isMatch(user,password)){
return true;
}
}
return false;
}
}
public class Review implements java.io.Serializable{
private String comment, name, restEventDesignation;
private double rating;
private String comment, name, restEventDesignation,eventType;
private Integer rating;
/**
* Review object structure
......@@ -9,11 +9,12 @@ public class Review implements java.io.Serializable{
* @param rating A rating
*/
public Review( String comment, String name, String restEventDesignation, double rating){
public Review( String comment, String name, String restEventDesignation, Integer rating, String restOrEvent){
this.name = name;
this.restEventDesignation = restEventDesignation;
this.comment = comment;
this.rating = rating;
this.eventType = restOrEvent;
}
public double getRating() {
......
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class ReviewRecieveThread implements Runnable{
Model usingModel;
public ReviewRecieveThread(Model newModel){
usingModel = newModel;
}
@Override
public void run() {
//ServerUser addUser;
//Review newReview;
String user, pass, eventType, eventName, rating, review;
int portNumber = 8001;
while(true) {
try (ServerSocket userServer = new ServerSocket(portNumber);
Socket clientSocket = userServer.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()))
) {
System.out.println("got connection to add review");
user = in.readLine();
pass = in.readLine();
eventType = in.readLine();
eventName = in.readLine();
rating = in.readLine();
review = in.readLine();
//Someone may have creating a user profile and not connected
//to the server, so let's check. If this was the case we will
//add them as a user
if (!usingModel.usersContains(user,pass)){
usingModel.addUser(new ServerUser(user,pass));
}
usingModel.addReview(new Review(review,user,eventName,Integer.getInteger(rating),eventType));
} catch (IOException e) {
continue;
}
}
}
}
public class ServerUser implements java.io.Serializable {
private String name,address;
private String name,address,password;
public ServerUser(String newName, String newAddress) {
public ServerUser(String newName, String uPass) {
name = newName;
address = newAddress;
password = uPass;
//was unable to pull address from android device
address = null;
}
@Override
public String toString() {
return super.toString();
}
public boolean isMatch(String user,String pass){
return (user.equalsIgnoreCase(this.name)) && (pass.equals(password));
}
}
......@@ -5,11 +5,17 @@ import java.net.ServerSocket;
import java.net.Socket;
public class UserReThread implements Runnable{
Model usingModel;
UserReThread(Model newModel){
usingModel = newModel;
}
@Override
public void run() {
ServerUser newUser;
String user, pass;
String message;
int portNumber = 8000;
System.out.println("Thread user is running and listening at port: "+portNumber);
while (true) {
......@@ -17,11 +23,10 @@ public class UserReThread implements Runnable{
Socket clientSocket = userServer.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()))
) {
System.out.println("got connection");
System.out.println(in.readLine());
System.out.println(in.readLine());
System.out.println(in.readLine());
System.out.println("got connection to add user");
user = in.readLine();
pass = in.readLine();
usingModel.addUser(new ServerUser(user,pass));
} catch (IOException e) {
continue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment