aboutsummaryrefslogtreecommitdiff
path: root/CS2452/assign5/src/WRServer.java
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-02-18 08:10:10 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-02-18 08:10:10 -0500
commitb4dbd2cfa724476162fa6d35941a5d7cdc9c9524 (patch)
tree431af0b75efa29dfa3bab2868a78ab0eb29173c7 /CS2452/assign5/src/WRServer.java
parente8b1808eaf87a49e4c34ebbfb66854baa627418c (diff)
Adds all assignments not previously in a git repo
Diffstat (limited to 'CS2452/assign5/src/WRServer.java')
-rwxr-xr-xCS2452/assign5/src/WRServer.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/CS2452/assign5/src/WRServer.java b/CS2452/assign5/src/WRServer.java
new file mode 100755
index 0000000..eadddc3
--- /dev/null
+++ b/CS2452/assign5/src/WRServer.java
@@ -0,0 +1,59 @@
+import java.io.*;
+import java.net.*;
+import java.util.concurrent.Semaphore;
+
+class WRServer implements Runnable
+{
+ int port;
+ Thread t;
+ byte[] theSharedResource = null;
+ Semaphore flg = null;
+ Semaphore flg2 = null;
+
+ WRServer(int p)
+ {
+ port = p;
+ theSharedResource = new byte[1024 * 1024];
+ flg = new Semaphore(1);
+ flg2 = new Semaphore(2);
+ t = new Thread(this, "WRServer");
+ t.start();
+ }
+
+ public void run()
+ {
+ ServerSocket ss = null;
+ Socket s = null;
+ DataOutputStream dout = null;
+ boolean running = true;
+ System.out.println("WRServer is alive");
+
+ ResourceWriter rw = new ResourceWriter(theSharedResource, flg, flg2);
+
+ try
+ {
+ ss = new ServerSocket(port);
+ } catch (Exception e0)
+ {
+ e0.printStackTrace();
+ }
+
+ while (running)
+ {
+ try
+ {
+ System.out.println("WRServer: waiting for incoming connection");
+ s = ss.accept();
+ System.out.println("WRServer: received incoming connection");
+
+ dout = new DataOutputStream(s.getOutputStream());
+ ResourceReader rr = new ResourceReader(dout, theSharedResource, flg, flg2);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ System.out.println("WRServer is finished");
+ }
+}