Cyber Final
Cyber Final
import java.io.*;
import java.net.*;
int offset = 0;
if (bytesToSend > 0) {
offset += bytesToSend;
if (availableBuffer == 0) {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
import java.net.*;
DataInputStream in = new
DataInputStream(socket.getInputStream());
int bufferUsed = 0;
while (true) {
out.writeInt(availableBuffer);
if (availableBuffer > 0) {
if (bytesRead > 0) {
bufferUsed += bytesRead;
Thread.sleep(200);
bufferUsed = 0;
} catch (Exception e) {
e.printStackTrace();
}
ssthresh = cwnd / 2;
if (ssthresh == 0) ssthresh = 1;
cwnd = ssthresh;
retransmitPacket();
congestion = false;
Question 1: Write the portion of the server code that waits for a
client connection and prints the port numbers for the server and
client.
Answer:
java
Copy code
Socket s = ss.accept();
Question 2: Write the portion of the client code that sends messages to
the server until the message "stop" is entered.
Answer:
java
Copy code
while (!str.equals("stop")) {
str = read.readLine();
output.writeUTF(str);
Question 3: What will be the output if the client sends the following
messages: "Hi", "How are you?", "stop"?
Server Output:
plaintext
Copy code
Client Says: Hi
Answer:
java
Copy code
int messageCount = 0;
while (!str.equals("stop")) {
str = input.readUTF();
messageCount++;
Question 1: Write the portion of the server code that accepts a client
connection and assigns it to a new thread.
Answer:
java
Copy code
new_tunnel.start();
Server Output:
plaintext
Copy code
Server is connecting
Answer:
java
Copy code
switch (received) {
case "Date":
toreturn = fordate.format(date);
dos_tunnel.writeUTF(toreturn);
break;
case "Time":
toreturn = fortime.format(date);
dos_tunnel.writeUTF(toreturn);
break;
default:
dos_tunnel.writeUTF("Invalid input");
break;
java
Copy code