-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworking12.java
More file actions
38 lines (33 loc) · 1.26 KB
/
Networking12.java
File metadata and controls
38 lines (33 loc) · 1.26 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
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
/**
* Created by Admin on 27-04-2017.
*/
public class Networking12 {
static int port = 1414;
static class Server{
public static void main(String[] args) throws Throwable{
ServerSocket ss=new ServerSocket(port);
System.out.println("Server started.\nListening for connections on port number "+port);
while(true) {
Socket s = ss.accept();
DataInputStream dis = new DataInputStream(s.getInputStream());
System.out.println(dis.readUTF());
}
}
}
static class Client{
public static void main(String[] args) throws Exception{
Socket s=new Socket("localhost", port);
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
String temp;
Scanner in=new Scanner(System.in);
while((temp = in.nextLine()) != "exit") {
dos.writeUTF(temp);
}
}
}
}