-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavaServer.java
60 lines (46 loc) · 1.61 KB
/
JavaServer.java
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package JavaServer;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;/**
*
* @author SyedSumair
*/
public class JavaServer {
/**
* @param args the command line arguments
*/
public static void main() {
try {
ServerSocket server = new ServerSocket(3496);
System.out.println("Server Start on pot 3496");
while(true) {
Socket client = server.accept();
// Code to read client response
/*
InputStream in = client.getInputStream();
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1) {
String output = new String(buffer, 0, read);
System.out.print(output);
System.out.flush();
};
*/
// Sending client data
OutputStream out = client.getOutputStream();
byte[] b = ("Hello Sumair \n\r").getBytes("UTF-8");
while(true) {
out.write(b);
}
}
} catch(Exception e) {
System.out.println(e.getMessage());
}
System.out.println("End of program...");
}
}