68 lines
1.7 KiB
Java
68 lines
1.7 KiB
Java
package client;
|
|
|
|
/**
|
|
* @author berdan
|
|
*/
|
|
|
|
|
|
import java.net.*;
|
|
import java.io.*;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.FormatStyle;
|
|
|
|
|
|
|
|
public class Client1 {
|
|
public Client1() throws IOException, ClassNotFoundException {
|
|
Socket socket = new Socket( "localhost", 1236 );
|
|
ObjectOutputStream oboust = new ObjectOutputStream(socket.getOutputStream());
|
|
ObjectInputStream obinstr = new ObjectInputStream(socket.getInputStream());
|
|
|
|
Message senden = new Message( "berdan", "test" );
|
|
System.out.println(senden);
|
|
|
|
// Message senden
|
|
oboust.writeObject(senden);
|
|
oboust.flush();
|
|
|
|
// Message erhalten
|
|
Object erhalten = obinstr.readObject();
|
|
System.out.println(erhalten);
|
|
|
|
oboust.close();
|
|
obinstr.close();
|
|
}
|
|
|
|
public static void main(String args[]) throws IOException, ClassNotFoundException {
|
|
new Client1();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class Message implements Serializable {
|
|
String username;
|
|
String message;
|
|
//String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
|
|
LocalDateTime current = LocalDateTime.now();
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
|
|
String date = current.format(formatter);
|
|
|
|
|
|
public Message( String username, String message ){
|
|
this.username = username;
|
|
this.message = message;
|
|
//this.date = date;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "nickname=" + username +
|
|
", message=" + message +
|
|
", time=" + date;
|
|
}
|
|
|
|
} |