first commit
This commit is contained in:
32
CS2335/lab4/Lab_files/Examples/Networking/ClientExample.java
Normal file
32
CS2335/lab4/Lab_files/Examples/Networking/ClientExample.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
class ClientExample {
|
||||
public static final int PORT = 1234;
|
||||
|
||||
public static void main(String argv[]) {
|
||||
try {
|
||||
Socket s = new Socket("localhost", PORT);
|
||||
BufferedReader br = new BufferedReader(new
|
||||
InputStreamReader(s.getInputStream()));
|
||||
PrintWriter pr = new PrintWriter(new
|
||||
OutputStreamWriter(s.getOutputStream()));
|
||||
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
|
||||
|
||||
System.out.println(s.getLocalAddress().toString());
|
||||
System.out.println(s.getLocalSocketAddress().toString());
|
||||
|
||||
String message = null;
|
||||
|
||||
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
while((message = stdIn.readLine()) != null) {
|
||||
System.out.println("Sending message: " + message);
|
||||
oos.writeObject(new TextMessage(message));
|
||||
oos.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("IO Exception: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user