-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
125 lines (90 loc) · 2.86 KB
/
Server.java
File metadata and controls
125 lines (90 loc) · 2.86 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
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
public class Server {
// TODO : Define all required varible
private ItemMap item_map;
ServerSocket Trade_server,Trade_publisher;
static Map <Integer,ArrayList> mapId=new HashMap<>();;
static long bid_time=System.currentTimeMillis();
public Server(ItemMap item_map) {
this.item_map = item_map;
}
public void start() throws IOException {
Runnable client_run=new Runnable() {// thread for port 2021
public void run() {
try {
ServerSocket ss=new ServerSocket(2021);// creating a port using a thread
int count=1;
while(true) {
Socket Client_socket =ss.accept();
System.out.println("Connection Success..... Client "+(count++)+" connected ");
ClientThread ct=new ClientThread(Client_socket,item_map);
Thread client=new Thread(ct);
client.start();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
Runnable publisher_run=new Runnable() {// thread for port 2022
public void run() {
try {
ServerSocket ss=new ServerSocket(2022);
int count=1;
while(true) {
Socket Publisher_Thread =ss.accept();
System.out.println("Connection Success..... Publisher "+(count++)+" connected ");
PublisherThread pt=new PublisherThread(Publisher_Thread,item_map);
Thread publisher=new Thread(pt);
publisher.start();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
Thread client_thread =new Thread(client_run);
Thread publisher_thread= new Thread(publisher_run);
client_thread.start();
publisher_thread.start();
}
public static int checkarray(float [] array,PrintWriter out) {// this method will give result for the user input symbol is valid or not
boolean tr=true;
String str="";
int o=0;
for(float k:array) {
if(k!= -1)
str+="0 ";
else {
tr=false;
str+="-1 ";
}
}
out.println(str);
if(tr==true)
o=0;
else if(tr==false)
o=-1;
return o;
}
public static boolean validate_input(String input){
boolean rtn=true;
for(int i=0;i<input.length();i++)
{
if(input.charAt(i)>=33 && input.charAt(i)<46 || input.charAt(i)>=58 &&input.charAt(i)<=64 ||input.charAt(i)>=91 &&input.charAt(i)<=96 || input.charAt(i)>=123)
{
rtn=false;
break;
}
}
return rtn;
}
}