Note that there are some explanatory texts on larger screens.

plurals
  1. POClient-Server 2 way communication unsuccessful (Perl)
    primarykey
    data
    text
    <p><strong>REQ FLOW :</strong></p> <pre><code>____________ LOGIN ___________ | |-------------------&gt;&gt;| | | CLIENT | LOGIN ACK | SERVER | |__________|&lt;&lt;------------------ |__________| </code></pre> <p>The client and the server sends across the contents of the files they open.</p> <p><strong>CODE:</strong></p> <p><strong><em>SERVER</em></strong> </p> <pre><code>$socket = new IO::Socket::INET ( LocalHost =&gt; '127.0.0.1', LocalPort =&gt; '0155', Proto =&gt; 'tcp', Listen =&gt; 1, Reuse =&gt; 1 ) or die "Oops: $! \n"; print "Waiting for the Client.\n"; while($clientsocket = $socket-&gt;accept()){ print "Connected from : ", $clientsocket-&gt;peerhost(); print ", Port : ", $clientsocket-&gt;peerport(), "\n"; while(&lt;$clientsocket&gt;){ if($_ ne "\$END\$\n"){ print"Message received from Client : $_"; print $clientsocket $_; } else{ print"\$END\$\n"; } } last; } login_ack(); sub login_ack{ # Some code removed for the purpose of posting open (LOGINACK, "login_ack.txt") || die "Cannot open login acknowledgment file $!\n"; my @loginack=&lt;LOGINACK&gt;; close LOGINACK; open(LOG, "&gt;&gt;logfile.txt"); foreach $loginack(@loginack) { if($loginack ne "\$END\$\n"){ print $clientsocket $loginack; print LOG $loginack; print $loginack; } else{ print"\$END\$\n"; } } </code></pre> <p><strong><em>CLIENT</em></strong></p> <pre><code>$socket = new IO::Socket::INET ( PeerHost =&gt; '127.0.0.1', PeerPort =&gt; '0155', Proto =&gt; 'tcp', Reuse =&gt; 1) or die "$!\n"; print "Connected to the Server.\n"; send_login(); sub send_login{ # Some code removed for the purpose of posting open (LOGIN, "Login.txt") || die "Cannot open login file $!\n"; my @login=&lt;LOGIN&gt;; close LOGIN; open(LOG, "&gt;&gt;logfile.txt"); foreach $login(@login) { if($login ne "\$END\$\n"){ print $socket $login; print LOG $login; print $login; } else{ print"\$END\$\n"; } } } LOGINACK : while(&lt;$socket&gt;){ print"Message received from Server : $_"; print $socket $_; last LOGINACK; } </code></pre> <p><strong>PRESENT OUTPUT:</strong></p> <p><img src="https://i.stack.imgur.com/A1jHC.png" alt="enter image description here"></p> <p><strong>DESIRED OUTPUT:</strong></p> <p><strong><em>CLIENT</em></strong></p> <pre><code>Connected to the Server. this is Login SAS4 50 SAS_ACTION LOGIN LOGIN bss PASSWORD cleint $END$ Message received from Server : this is Login Ack Message received from Server : SAS4 Message received from Server : 61 Message received from Server : SAS_ACTION LOGIN_ACK Message received from Server : ACK_STATUS 0 Message received from Server : ACK_MESSAGE Logged In Message received from Server : $END$ </code></pre> <p><strong><em>SERVER</em></strong></p> <pre><code>Waiting for the Client. Connected from : 127.0.0.1, Port : 1862 Message received from Client : this is Login Message received from Client : SAS4 Message received from Client : 50 Message received from Client : SAS_ACTION LOGIN Message received from Client : LOGIN bss Message received from Client : PASSWORD cleint Message received from Client : $END$ this is Login Ack SAS4 61 SAS_ACTION LOGIN_ACK ACK_STATUS 0 ACK_MESSAGE Logged In $END$ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload