-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.java
More file actions
59 lines (59 loc) · 1.95 KB
/
Copy pathclient.java
File metadata and controls
59 lines (59 loc) · 1.95 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
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
import java.io.*;
import java.net.*;
import java.util.Scanner;
class client
{
public static void main(String args[])throws IOException
{
Scanner sc=new Scanner(System.in);
String IP;
int port;
System.out.print("Enter the IP of server : ");
IP=sc.nextLine();
System.out.print("Enter the port : ");
port=sc.nextInt();
Socket s=new Socket(IP,port);
DataInputStream dis=new DataInputStream(s.getInputStream());
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
String message;
DateTimeFormatter dtf=DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDateTime now=LocalDateTime.now();
System.out.print("Enter your username : ");
String serverus;
String str=sc.next();
serverus=dis.readUTF();
dos.writeUTF(str);
File f=new File("D:\\"+str+" to "+serverus+".txt");
FileWriter fw=new FileWriter(f,true);
PrintWriter pw=new PrintWriter(fw);
pw.println();
fw.write(dtf.format(now));
fw.close();
while(true)
{
dtf=DateTimeFormatter.ofPattern("HH:mm");
fw=new FileWriter(f,true);
pw=new PrintWriter(fw);
System.out.print(str+" : ");
message=sc.nextLine();
now=LocalDateTime.now();
fw.write(dtf.format(now));
pw.println();
fw.write(str+" : "+message);
pw.println();
pw.println();
dos.writeUTF(message);
message=dis.readUTF();
now=LocalDateTime.now();
System.out.println(serverus+" : "+message);
fw.write(dtf.format(now));
pw.println();
fw.write(serverus+" : "+message);
pw.println();
pw.println();
fw.close();
}
};
};