-
Notifications
You must be signed in to change notification settings - Fork 0
/
p2.java
40 lines (33 loc) · 918 Bytes
/
p2.java
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
import java.io.*;
import java.net.*;
public class p2
{
public static void main(String args[])
{
try
{
System.out.println("P2 Running...");
ServerSocket ss = new ServerSocket(4405);
Socket con = ss.accept();
DataInputStream input = new DataInputStream(con.getInputStream());
String msg = input.readUTF();
System.out.println("Message Received: " + msg);
Socket fs = new Socket("127.0.0.1",5506);
DataOutputStream out = new DataOutputStream(fs.getOutputStream());
if(msg.length() < 100)
{
out.writeUTF(msg);
System.out.println("Message Forwarded to P3..");
}
else
{
System.out.println("Message not sent!");
System.out.println("Message length exceeds the set value. \nMessage length:\t " + msg.length());
}
}
catch(Exception e)
{
System.out.println("Something went wrong: " + e);
}
}
}