-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignificanlytested.txt
More file actions
858 lines (667 loc) · 21.5 KB
/
significanlytested.txt
File metadata and controls
858 lines (667 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
import java.util.StringTokenizer;
class PeerWorker implements Runnable {
Socket client = null;
public PeerWorker(Socket temp, int port) throws UnknownHostException,
IOException {
client = temp;
}
public PeerWorker() {
}
public void sendMessageTo(String address, CANMessage message)
throws NumberFormatException, UnknownHostException, IOException {
String host[] = address.split(":");
Socket socket = new Socket(host[0], Integer.parseInt(host[1]));
ObjectOutputStream out = new ObjectOutputStream(
socket.getOutputStream());
out.writeObject(message);
out.close();
socket.close();
}
public void greedyRoute(CANMessage message) {
ObjectOutputStream out;
BufferedReader in;
InputStreamReader ir;
try {
// System.out.println("List of neighbours " + Peer.neighbours);
ArrayList<ArrayList<Double>> distanceMatrix = getDistanceMatrix(message.destination);
String nextHop = getNextHop(distanceMatrix);
// System.out.println("Greedy route next hop is:" + nextHop);
sendMessageTo(nextHop, message);
// String host[] = nextHop.split(":");
//
// Socket socket = new Socket(host[0], Integer.parseInt(host[1]));
//
// out = new ObjectOutputStream(socket.getOutputStream());
//
// // System.out.println("Sending greedily to " + nextHop
// // + "and destination in message is "
// // + message.destination.toString());
//
// out.writeObject(message);
// out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private String getNextHop(ArrayList<ArrayList<Double>> distanceMatrix) {
int x = 0, y = 0;
double min = Double.MAX_VALUE;
for (int i = 0; i < distanceMatrix.size(); i++) {
ArrayList<Double> direction = distanceMatrix.get(i);
for (int j = 0; j < direction.size(); j++) {
if (direction.get(j) < min) {
min = direction.get(j);
x = i;
y = j;
}
}
}
String nextHop = Peer.neighbours.get(x).get(y);
return nextHop;
}
private ArrayList<ArrayList<Double>> getDistanceMatrix(Point destination)
throws UnknownHostException, IOException {
CANMessage getDistance = new CANMessage("distance", Peer.CANid,
destination);
ObjectOutputStream out;
BufferedReader in;
InputStreamReader ir;
ArrayList<ArrayList<Double>> distanceMatrix = new ArrayList<ArrayList<Double>>();
for (int i = 0; i < Peer.neighbours.size(); i++) {
distanceMatrix.add(new ArrayList<Double>());
ArrayList<String> direction = Peer.neighbours.get(i);
if (direction.isEmpty())
continue;
for (int j = 0; j < direction.size(); j++) {
String neighbor = direction.get(j);
String host[] = neighbor.split(":");
// System.out.println("Fetching distance from " + host[0] +
// " at "
// + host[1]);
Socket socket = new Socket(host[0], Integer.parseInt(host[1]));
out = new ObjectOutputStream(socket.getOutputStream());
out.writeObject(getDistance);
ir = new InputStreamReader(socket.getInputStream());
in = new BufferedReader(ir);
double reply = Double.parseDouble(in.readLine());
out.close();
in.close();
distanceMatrix.get(i).add(reply);
socket.close();
}
}
return distanceMatrix;
}
double getDistanceToPoint(Point destination) {
double distance = Peer.peerZone.getDistanceToPoint(destination);
return distance;
}
void InitiateNodeJoin(String node) {
ObjectOutputStream out;
try {
// Create new zone, neighbors and file list.
Zone newZone = null;
ArrayList<ArrayList<String>> neighboursToSend = new ArrayList<ArrayList<String>>();
HashMap<String, String> files = new HashMap<String, String>();
int count = 0;
getCopyOfNeighbors(neighboursToSend);
if (Peer.peerZone.isZoneSquare()) {
newZone = Peer.peerZone.splitVertically();
files = new HashMap<String, String>();
Iterator<Map.Entry<String, String>> iter = Peer.files
.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, String> entry = iter.next();
Point hash = Peer.getHashFileName(entry.getKey());
if (newZone.isPointInZone(hash)) {
files.put(entry.getKey(), entry.getValue());
iter.remove();
}
}
// Clear all left neighbors.
neighboursToSend.get(0).clear();
// // Add self
neighboursToSend.get(0).add(Peer.CANid);
CANMessage message = new CANMessage("delete", Peer.CANid, 0);
// Update this nodes right neighbors to remove it.
for (String neighbor : Peer.neighbours.get(2)) {
// String host[] = neighbor.split(":");
//
// Socket socket = new Socket(host[0],
// Integer.parseInt(host[1]));
// System.out.println("sending delete vert " + host[0]);
// out = new ObjectOutputStream(socket.getOutputStream());
sendMessageTo(neighbor, message);
//
// out.writeObject(message);
// out.close();
}
// Add new node to list of my neighbors on the right.
Peer.neighbours.get(2).clear();
Peer.neighbours.get(2).add(node);
} else {
newZone = Peer.peerZone.splitHorizontally();
files = new HashMap<String, String>();
Iterator<Map.Entry<String, String>> iter = Peer.files
.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, String> entry = iter.next();
Point hash = Peer.getHashFileName(entry.getKey());
if (newZone.isPointInZone(hash)) {
files.put(entry.getKey(), entry.getValue());
iter.remove();
}
}
// Clear all bottom neighbors.
neighboursToSend.get(3).clear();
// Add self as bottom neighbor
neighboursToSend.get(3).add(Peer.CANid);
CANMessage message = new CANMessage("delete", Peer.CANid, 3);
// Update this nodes top neighbors to remove it.
for (String neighbor : Peer.neighbours.get(1)) {
// String host[] = neighbor.split(":");
//
// Socket socket = new Socket(host[0],
// Integer.parseInt(host[1]));
// // System.out.println("sending delete to horiz " + host[0]);
// out = new ObjectOutputStream(socket.getOutputStream());
//
// CANMessage message = new CANMessage("delete", Peer.CANid, 3);
//
// out.writeObject(message);
// out.close();
// System.out.println("sent horiz");
sendMessageTo(neighbor, message);
}
// Add new node to list of my neighbors on top
Peer.neighbours.get(1).clear();
Peer.neighbours.get(1).add(node);
}
CANMessage welcome = new CANMessage("welcome", newZone,
neighboursToSend, files);
sendMessageTo(node, welcome);
// String host[] = node.split(":");
//
// Socket socket = new Socket(host[0], Integer.parseInt(host[1]));
//
// ObjectOutputStream returnOut;
// returnOut = new ObjectOutputStream(socket.getOutputStream());
//
// // Send zone, neighbor and file list to new peer.
//
// CANMessage welcome = new CANMessage("welcome", newZone,
// neighboursToSend, files);
//
// returnOut.writeObject(welcome);
// returnOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void getCopyOfNeighbors(
ArrayList<ArrayList<String>> neighboursToSend) {
for (int i = 0; i < Peer.neighbours.size(); i++) {
neighboursToSend.add(new ArrayList<String>());
ArrayList<String> direction = Peer.neighbours.get(i);
if (direction.isEmpty())
continue;
for (int j = 0; j < direction.size(); j++) {
neighboursToSend.get(i).add(direction.get(j));
}
}
}
void serviceMessage(CANMessage message) throws IOException {
// Peer wants to join
if (message.requestType.equals("join")) {
InitiateNodeJoin(message.source);
}
else if (message.requestType.equals("found")
|| message.requestType.equals("notfound")) {
if (message.requestType.equals("found"))
System.out.println("File found at : " + message.messageFrom);
else
System.out.println("Failure.");
}
// Calculating distance for greedy routing.
else if (message.requestType.equals("distance")) {
double distance = getDistanceToPoint(message.destination);
PrintStream out = new PrintStream(client.getOutputStream());
out.println(distance);
}
// Updating neighbors
else if (message.requestType.equals("update")) {
// System.out.println("Adding " + message.source + " to "
// + message.side);
if (!Peer.neighbours.get(message.side).contains(message.source))
Peer.neighbours.get(message.side).add(message.source);
}
// Deleting neighbors
else if (message.requestType.equals("delete")) {
// System.out.println("Deleting " + message.source + " from "
// + message.side);
Peer.neighbours.get(message.side).remove(message.source);
}
else if (message.requestType.equals("welcome")) {
System.out.println("Join successfull. Fetching details...");
getJoinDetails(message);
}
// Insert file at this location
else if (message.requestType.equals("insert")) {
insertFile(message);
}
// Insertion confirmation.
else if (message.requestType.equals("inserted")) {
System.out.println(message.message + " " + message.messageFrom);
}
else if (message.requestType.equals("search")) {
checkForFile(message);
}
}
private void checkForFile(CANMessage message) throws IOException {
String status = "notfound";
System.out.println("Searching for " + message.file);
if (Peer.files.containsKey(message.file)) {
status = "found";
}
CANMessage searchStatus = new CANMessage(status, "", Peer.hostName
+ " " + Peer.CANid);
sendMessageTo(message.source, searchStatus);
// String host[] = message.source.split(":");
// Socket socket = new Socket(host[0], Integer.parseInt(host[1]));
//
// ObjectOutputStream out = new ObjectOutputStream(
// socket.getOutputStream());
// out.writeObject(searchStatus);
// out.close();
// socket.close();
}
private void insertFile(CANMessage message) {
Peer.files.put(message.file, message.file);
// System.out.println("File stored in :" + Peer.CANid);
//
// String source = message.source;
//
// String host[] = source.split(":");
try {
CANMessage confirm = new CANMessage("inserted", "File inserted at "
+ Peer.hostName, Peer.CANid);
sendMessageTo(message.source, confirm);
// Socket socket = new Socket(host[0], Integer.parseInt(host[1]));
//
// ObjectOutputStream out = new ObjectOutputStream(
// socket.getOutputStream());
// out.writeObject(confirm);
// out.close();
// socket.close();
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void getJoinDetails(CANMessage message) {
Peer.peerZone = (Zone) message.newZone;
Peer.neighbours = (ArrayList<ArrayList<String>>) message.neighbors;
Peer.files = (HashMap<String, String>) message.files;
Peer.isInCAN = true;
Peer.informNeighborsOfExistence();
}
private void processMessage(CANMessage message) throws IOException {
// ln("got message" + message.requestType + " "
// + message.destination);
// Directly received messages
if (message.requestType.equals("update")
|| message.requestType.equals("delete")
|| message.requestType.equals("welcome")
|| message.requestType.equals("distance")
|| message.requestType.equals("inserted")
|| message.requestType.equals("found")
|| message.requestType.equals("notfound")) {
serviceMessage(message);
}
else if (Peer.peerZone.isPointInZone(message.destination)) {
serviceMessage(message);
}
else {
// System.out.println("greedy route to point");
greedyRoute(message);
}
}
public void run() {
try {
if (client == null)
System.out.println("NULL MOTHERFUCKER!!");
else {
ObjectInputStream ipReader = new ObjectInputStream(
client.getInputStream());
// read CAN message from peer.
CANMessage message = (CANMessage) ipReader.readObject();
processMessage(message);
}
} catch (Exception exp) {
exp.printStackTrace();
}
}
}
class PeerBackground implements Runnable {
private static ServerSocket listeningSocket = null;
PeerBackground(int portForCAN) throws IOException {
listeningSocket = new ServerSocket(portForCAN);
}
public void run() {
while (true) {
try {
Socket client = listeningSocket.accept();
// Start listening for CAN messages.
new Thread(new PeerWorker(client, Peer.portforCAN)).start();
} catch (Exception e) {
e.printStackTrace();
}
continue;
}
}
public static void stopListening() {
try {
listeningSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class Peer {
public static Zone peerZone;
public static ArrayList<ArrayList<String>> neighbours = new ArrayList<ArrayList<String>>();
public static HashMap<String, String> files = new HashMap<>();
public static String bootStrap;
public static int bootstrapPort;
public static int portforCAN = 8888;
public static String ip = null;
public static String CANid = null;
public static String hostName = null;
public static boolean isInCAN = false;
Peer(String bootStrap, int port) {
Peer.bootstrapPort = port;
Peer.bootStrap = bootStrap;
for (int i = 0; i < 4; i++) {
neighbours.add(new ArrayList<String>());
}
try {
ip = InetAddress.getLocalHost().toString().split("/")[1];
hostName = InetAddress.getLocalHost().toString().split("/")[0];
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
private void sendJoinRequest(String response) throws UnknownHostException {
Point destination = getRandomPoint();
String ip = InetAddress.getLocalHost().toString().split("/")[1];
CANMessage message = new CANMessage("join", ip + ":"
+ String.valueOf(Peer.portforCAN), destination);
String host[] = response.split(":");
try {
// Create socket to entry point and specific port.
Socket socket = new Socket(host[0], Integer.parseInt(host[1]));
ObjectOutputStream output = new ObjectOutputStream(
socket.getOutputStream());
startListeningInCAN();
// Send out the join message.
output.writeObject(message);
} catch (Exception exp) {
exp.printStackTrace();
}
}
public static void informNeighborsOfExistence() {
// System.out.println("Updating neihbours:");
System.out.println(Peer.neighbours);
ObjectOutputStream out = null;
for (int i = 0; i < Peer.neighbours.size(); i++) {
ArrayList<String> direction = Peer.neighbours.get(i);
for (int j = 0; j < direction.size(); j++) {
String neighbor = direction.get(j);
String host[] = neighbor.split(":");
try {
Socket socket = new Socket(host[0],
Integer.parseInt(host[1]));
out = new ObjectOutputStream(socket.getOutputStream());
// System.out.println("Sending update to " + host[0] +
// " at "
// + host[1]);
CANMessage message = new CANMessage("update", Peer.CANid,
(i + 2) % 4);
out.writeObject(message);
out.close();
socket.close();
// System.out.println("sent update");
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
private Point getRandomPoint() {
Random r = new Random();
int x = r.nextInt(10);
int y = r.nextInt(10);
Point destination = new Point(x, y);
// System.out.println("Headed to : " + destination.toString());
return destination;
}
private void joinCAN() {
// Get port peer is dedicating to CAN
int port = getPortForCAN();
Socket socketToServer = new Socket();
try {
socketToServer.connect(new InetSocketAddress(bootStrap,
Peer.bootstrapPort));
} catch (IOException e) {
System.out.println(e.getMessage() + " to bootstrap server.");
}
try {
InputStreamReader ipreader = new InputStreamReader(
socketToServer.getInputStream());
BufferedReader input = new BufferedReader(ipreader);
PrintStream output = new PrintStream(
socketToServer.getOutputStream());
// System.out.println("here");
// Send join request and send port the peer has dedicated to CAN.
output.println("join");
output.println(portforCAN);
// Wait for response.
String response = input.readLine();
// First peer in CAN
if (response.equals("owner")) {
// Assign full space.
Peer.peerZone = new Zone(new Point(0.0, 0.0), new Point(10.0,
10.0));
isInCAN = true;
startListeningInCAN();
} else if (response.equals("unrecognizedcommand"))
System.out.println("Server did not recognize command");
else {
// Got entry point into CAN
// System.out.println("Entry point is: " + response);
sendJoinRequest(response);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void startListeningInCAN() throws IOException {
new Thread(new PeerBackground(Peer.portforCAN)).start();
}
private int getPortForCAN() {
System.out.print("Port dedictaed to CAN : ");
Scanner in = new Scanner(System.in);
int port = in.nextInt();
Peer.portforCAN = port;
Peer.CANid = ip + ":" + String.valueOf(Peer.portforCAN);
return port;
}
private void viewDetails() {
System.out.println();
try {
System.out.println("Name: "
+ InetAddress.getLocalHost().getCanonicalHostName());
} catch (UnknownHostException e) {
e.printStackTrace();
}
System.out.println("Zone: " + Peer.peerZone.toString());
// Printing neighbor details
System.out.println("Neighbors:");
int count = 0;
for (ArrayList<String> direction : neighbours) {
if (!direction.isEmpty()) {
if (count == 0)
System.out.print(" Left: ");
else if (count == 1)
System.out.print(" Top:");
else if (count == 2)
System.out.print(" Right: ");
else
System.out.print(" Bottom: ");
System.out.println(direction);
}
count++;
}
System.out.println("Files:");
System.out.print(" ");
for (String filename : files.keySet()) {
System.out.print(filename + " ");
}
System.out.println();
}
private static void search(String filename) {
Point locationOfFile = getHashFileName(filename);
if (peerZone.isPointInZone(locationOfFile)) {
if (files.keySet().contains(filename))
System.out.println("File is here with you at " + hostName + " "
+ CANid);
else
System.out.println("Failure?!?!?! wtf?!?!");
}
// else release into CAN.
else {
// System.out.println("file not at local disk. Searching network...");
PeerWorker worker = new PeerWorker();
CANMessage search = new CANMessage("search", CANid, locationOfFile,
filename);
worker.greedyRoute(search);
}
}
private void insertFile(String filename) {
Point insertionPoint = getHashFileName(filename);
System.out.println(filename + " inserted at " + insertionPoint.toString());
// Check if destination is in own zone and insert.
if (peerZone.isPointInZone(insertionPoint))
files.put(filename, filename);
// else release into CAN.
else {
PeerWorker worker = new PeerWorker();
CANMessage insert = new CANMessage("insert", this.CANid,
insertionPoint, filename);
worker.greedyRoute(insert);
}
}
public static Point getHashFileName(String filename) {
int odd = 0, even = 0;
// Calculate hash for filename.
for (int i = 1; i < filename.length(); i += 2) {
odd += filename.charAt(i);
}
for (int i = 0; i < filename.length(); i += 2) {
even += filename.charAt(i);
}
// Get point where file will be inserted
Point insertionPoint = new Point(odd % 10, even % 10);
return insertionPoint;
}
public void processCommand(String command) throws Exception {
StringTokenizer tokens = new StringTokenizer(command);
if (!tokens.hasMoreTokens())
throw new Exception("Invalid command");
String comm = tokens.nextToken();
if (comm.equalsIgnoreCase("stop")) {
PeerBackground.stopListening();
}
// Check if already in can, else start join process.
if (comm.equalsIgnoreCase("join")) {
if (isInCAN)
throw new Exception("Already in CAN.");
joinCAN();
}
else {
if (!isInCAN)
throw new Exception("Need to join CAN first.");
if (comm.equalsIgnoreCase("view")) {
viewDetails();
}
else if (comm.equalsIgnoreCase("leave")) {
// call leave
}
else if (comm.equalsIgnoreCase("search")) {
String keyword = tokens.nextToken();
if (keyword.isEmpty() || keyword == null) {
throw new Exception("Keyword missing");
}
search(keyword);
}
else if (comm.equalsIgnoreCase("insert")) {
String keyword = tokens.nextToken();
if (keyword.isEmpty() || keyword == null) {
throw new Exception("Keyword missing");
}
insertFile(keyword);
}
else
throw new Exception("Invalid command");
}
}
public static void main(String[] args) {
// String serverName = "129.21.37.35";
// int port = 1954;
String serverName = args[0];
int port = Integer.parseInt(args[1]);
Peer thisPeer = new Peer(serverName, port);
while (true) {
try {
System.out.print("Enter command: ");
Scanner in = new Scanner(System.in);
String command = in.nextLine();
thisPeer.processCommand(command);
} catch (Exception e) {
System.out.println(e.getMessage());
continue;
}
}
}
}