Neue Class "Client1" mit Message Object
This commit is contained in:
parent
318abd4930
commit
6f61fbeebe
3 changed files with 73 additions and 21 deletions
68
src/client/Client1.java
Normal file
68
src/client/Client1.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue