Home
Downloads
Projects
Forum
Portfolio
Contact
Ajinkya Mandhare
"The Goal is not to live forever...the goal is to create something that will"
Thursday, 31 March 2011
Tagged under:
Go back n
,
TE VI SEM
Go Back N - Sender & Receiver
Anonymous
7:20 am
No comment
1. Go Back N Sender:
import java.io.*; import java.net.*; import java.lang.*; public class gbnsend { public static void main(String args[]) { int serverport=3333; String address="127.0.0.2"; try { InetAddress ipaddress=InetAddress.getByName(address); Socket socket=new Socket(ipaddress,serverport); InputStream sin=socket.getInputStream(); OutputStream sout=socket.getOutputStream(); DataInputStream in=new DataInputStream(sin); DataOutputStream out=new DataOutputStream(sout); BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in)); String line=null; String word []=new String [8]; int i; System.out.println("plz input the no of frames to b sent"); int n=Integer.parseInt(keyboard.readLine()); for(i=0;i<n;i++) { word[i]=keyboard.readLine(); } i=0; while(i<n) { System.out.println("sending frame "+word[i]); out.writeUTF(word[i]); out.flush(); i++; } try { Thread.sleep(1000); } catch(InterruptedException e) { e.printStackTrace(); } line=in.readUTF(); System.out.println("nack received for frame "+line); i=Integer.parseInt(line); out.writeUTF(word[i]); System.out.println("retransmitting all frames after "+word[i]); i++; while(i<n) { System.out.println("sending frame "+word[i]); out.writeUTF(word[i]); out.flush(); i++; } } catch(Exception e) { e.printStackTrace(); } } }
2. Go Back N Receiver:
import java.net.*; import java.io.*; public class gbnreceive { public static void main(String args[]) { int port=3333; try { ServerSocket ss=new ServerSocket(port); System.out.println("waiting for user2"); Socket socket=ss.accept(); System.out.println("user detected"); System.out.println(); InputStream sin=socket.getInputStream(); OutputStream sout=socket.getOutputStream(); DataInputStream in=new DataInputStream(sin); DataOutputStream out=new DataOutputStream(sout); BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in)); String line=null; String word []=new String [8]; int i=0; while(i<4) { line=in.readUTF(); word[i]=line; System.out.println("frame "+word[i]+" received successfully"); i++; } while(i<8) { if(i==4) { System.out.println("frame "+i+" not received"); i++; } else { System.out.println("frame "+i+" discarded"); i++; } } System.out.println("requesting for retransmaission"); line=keyboard.readLine(); out.writeUTF(line); out.flush(); i=4; while(i<8) { line=in.readUTF(); word[i]=line; i++; } System.out.println("received all retransmitted frames successfully"); } catch(Exception e) { e.printStackTrace(); } /*finally { sin.close(); sout.close(); in.close(); out.close(); }*/ } }
Kindly Bookmark and Share it:
Newer Post
Older Post
0 comments:
Post a Comment
Subscribe to:
Post Comments (Atom)
Recommend us on Google!
RSS Feed
Twitter
Google Plus
Whats Hot This Week
Multi Window and Ripple Lock Screen for Samsung Galaxy S2 GT-i9100 Jelly Bean(4.1.2)
Samsung recently rolled out the JellyBean 4.1.2 update for Galaxy S2. The S2 users, including myself were eagerly awaiting this upgrade, an...
Zend Framework from Scratch Part II: MVC and Creating Zend Project
In the Part I of the 'Zend from Scratch' series, we installed Zend and configured the environment to create our first Zend pr...
Zend Framework from Scratch Part I: Install and Configure PHP Zend Framework
Zend Framework (ZF) is an open source, object-oriented, full-stack PHP framework created by Zend Technologies implemented in PHP 5 a...
Auto Refresh a Web Page using AJAX
AJAX is nothing but Asynchronous JavaScript and XML. It is not a new programming language, but a new way to use the existing standa...
Root Samsung Galaxy S2 GT-i9100 Jelly Bean and install Clockwork Recovery Mod
With the official Jelly Bean update now available for Galaxy SII, one thing that any android fan would be looking for would be 'How t...
Read an Excel file using PHP
Reading an excel file using some server-side scripting language is something that should be in the ammo of any developer. Now, Excel ...
Creating a Barcode in PHP
A barcode is an optical machine-readable representation of data relating to the object to which it is attached. Originally barcode...
Secure Login Code using PHP and MySQL / Preventing SQL Injection using PHP
Many Web pages accept parameters from web users and generate SQL queries to the database. SQL Injection is a trick to inject SQL script...
Forgot Password Functionality in PHP
When you implement a Login functionality, one thing that becomes an obvious inclusion is the 'Forgot Password' functionality. ...
Generating a Unique Hardware Fingerprint for Software Licensing
Generating a hardware fingerprint is the most commonly sought technique to ensure security in case of softwares. There can be various met...
Follow on FaceBook
0 comments:
Post a Comment