Skip to content
Snippets Groups Projects
Commit 09ed173d authored by ik1g19's avatar ik1g19
Browse files

add TCP apps

parent 2a3b4567
No related branches found
No related tags found
No related merge requests found
File added
import java.io.*;
import java.net.*;
class TCPReceiver {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(4322);
for (;;) {
try {
Socket client = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line;
while ((line = in .readLine()) != null) System.out.println(line + " received");
client.close();
} catch (Exception e) {
System.out.println("error " + e);
}
}
} catch (Exception e) {
System.out.println("error " + e);
}
}
}
File added
import java.io.*;
import java.net.*;
class TCPSender {
public static void main(String[] args) {
try {
Socket socket = new Socket("isaac-VirtualBox", 4322);
PrintWriter out = new PrintWriter(socket.getOutputStream());
for (int i = 0; i < 10; i++) {
out.println("TCP message " + i);
out.flush();
System.out.println("TCP message " + i + " sent");
Thread.sleep(1000);
}
} catch (Exception e) {
System.out.println("error" + e);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment