Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This project is an implementation of a TCP/IP communication, in order to properl

ID: 3685018 • Letter: T

Question

This project is an implementation of a TCP/IP communication, in order to properly test this simulation you need to create an client/server connection on local host, Code will be posted if you need additional help in this area. Some basic rules of client server are as follows:

The server can go down, the client will wait, when reconnected, all messages in progress will continue, as if they were not interrupted,

A client can be shut down, once restored, will continue with the interaction to the server.

There will be no data lost during the execution of the simulation, in either TCP or UDP The message that is sent by the server to each client, you may create your own message, but make sure it spans more than one packet.

I would also like to know how to make it run successfully in Wireshark and capture the require packets.

Thanks

here is the code:

import java.lang.*;

import java.io.*;

import java.net.*;

class Server {    public static void main(String args[])

{       String data = "Toobie ornaught toobie";      

try {          ServerSocket srvr = new ServerSocket(1234);

        Socket skt = srvr.accept();    

      System.out.print("Server has connected! ");   

       PrintWriter out = new PrintWriter(skt.getOutputStream(), true);     

     System.out.print("Sending string: '" + data + "' ");

        out.print(data);          out.close();

        skt.close();   

       srvr.close();   

    }      

catch(Exception e)

{          System.out.print("Whoops! It didn't work! ");       }

} }

(Client.java):

import java.lang.*;

import java.io.*

; import java.net.*;

class Client {    public static void main(String args[])

{      

try

{          Socket skt = new Socket("localhost", 1234);   

       BufferedReader in = new BufferedReader(new             InputStreamReader(skt.getInputStream()));

        System.out.print("Received string: '");    

      while (!in.ready()) {}      

    System.out.println(in.readLine()); // Read one line and output it       

   System.out.print("' ");       

   in.close();       }    

   catch(Exception e)

{          System.out.print("Whoops! It didn't work! ");     

}    } }

I cant make it work in Wireshark.

Explanation / Answer

I think all you want is just Client - Socket Program in Java and get captured these packets in Wireshark , during this communication

You can refer Here's Simple Client Server Program To use TC/IP Communication .

- Please Ensure You Open 2 different tabs of terminal for Sever program and Client Program

---------e.g Run this on one terminal tab   

javac Server.java

java Server

---------------and this on another terminal tab

javac Client.java

java Client

-----------------------You can refer following Souce Code For This which is Simper to understand :-

// Client Class

import java.net.*;

import java.io.*;

public class Client

{

   public static void main(String [] args)

   {

String serverName = "localhost";

int port = 12345;

try

{

   System.out.println("Connecting to " + serverName +

       " on port " + port);

   Socket client = new Socket(serverName, 12345);               //port=12345

   System.out.println("Just connected to "

       + client.getRemoteSocketAddress());

   OutputStream outToServer = client.getOutputStream();

   DataOutputStream out = new DataOutputStream(outToServer);

   out.writeUTF("Hello from "

+ client.getLocalSocketAddress());

   InputStream inFromServer = client.getInputStream();

   DataInputStream in =

new DataInputStream(inFromServer);

   System.out.println("Server says " + in.readUTF());

   client.close();

}catch(IOException e)

{

   e.printStackTrace();

}

   }

}

// Server Class :-

// File Name GreetingServer.java

import java.net.*;

import java.io.*;

public class Server extends Thread

{

   private ServerSocket serverSocket;

   public Server(int port) throws IOException

   {

serverSocket = new ServerSocket(port);

serverSocket.setSoTimeout(60000);

   }

   public void run()

   {

while(true)

{

   try

   {

System.out.println("Waiting for client on port " +

serverSocket.getLocalPort() + "...");

Socket server = serverSocket.accept();

System.out.println("Just connected to "

+ server.getRemoteSocketAddress());

DataInputStream in =

new DataInputStream(server.getInputStream());

System.out.println(in.readUTF());

DataOutputStream out =

   new DataOutputStream(server.getOutputStream());

out.writeUTF("Thank you for connecting to "

+ server.getLocalSocketAddress() + " Goodbye!");

server.close();

   }catch(SocketTimeoutException s)

   {

System.out.println("Socket timed out!");

break;

   }catch(IOException e)

   {

e.printStackTrace();

break;

   }

}

   }

   public static void main(String [] args)

   {

int port = 12345;

try

{

   Thread t = new Server(port);

   t.start();

}catch(IOException e)

{

   e.printStackTrace();

}

   }

}

----------------------------------------------Note -----------------------------------------------------------------------------------

Before Capturing packets in Wireshark Please Ensure that you have Proper Filter preference in Wireshark :-

https://wiki.wireshark.org/CaptureFilters

Set this Before Running Above Programs.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote