-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.java
68 lines (59 loc) · 1.61 KB
/
server.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
61
62
63
64
65
66
67
68
import java.io.*;
import java.util.*;
import java.net.*;
public class server
{
public server(){}
public static void main(String args[])
{
(new Listener()).start();
/*
try
{
//Connecting to Network
String ip = "localhost";
int network = 6538;
Socket clientSocket = new Socket(ip, network);
DataOutputStream output = new DataOutputStream(clientSocket.getOutputStream());
while(true)
{
String msg = "6539,Ping from Node.";
output.write(msg.getBytes()); //send message
System.out.println("Pinged Server");
Thread.sleep(2000);
}
}
catch(Exception e)
{
System.out.println("Exception: " + e);
}
*/
}
}
class Listener extends Thread
{
public Listener() {}
public void run()
{
try
{
System.out.println("server not started!");
int port = 6580;
ServerSocket server = new ServerSocket(port);
System.out.println("server started!");
Socket socket = server.accept();
DataInputStream input = new DataInputStream(socket.getInputStream());
while(true)
{
byte[] buff = new byte[1024];
input.read(buff);
String read = new String(buff);
System.out.println(read);
}
}
catch (Exception e)
{
System.out.println("Listener Exception: " + e);
}
}
}