DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 3rd May 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Arrow Java socket programming question

It is the 1st time I seft-study Java and socket programming, and I just started about a week ago, so bear with me.

What Im trying to do is create a network of 3 machines, server, relay and client for reliable data transfer. The client and server dont communicate directly, but via the relay. The client sends a number of packets, one by one, some of them will be dumped (dropped) at the relay.

The reliable transfer method will be implement like this

- Create a protocol.

- Use sequence number. For instance, if the server receives packet which sequence numbers are 1, 2 but the next one is 4, not 3 as expected, it will send a NACK to the relay, the relay now forward the NACK to the client. The client has 2 options, if it is an ACK, sends the packet with the next sequence number, if it is a NACK, retransmit the previous packet.

- Use the timer. Once received packet x, the server sets timeout for the next packet. If timeout is reached, it will send a NACK, and the client will restransmit the packet.

So what I have done is create a protocol, set up a communication between the client and relay. Now I get stuck because I dont know how to implement the sequence number.

I did a search on Google and found 2 functions:

Code:
getSequenceNumber()
setSequenceNumber()
But I think I have a brainstorm atm, can anyone gives me a simple example how to use those functions please.
Reply With Quote
  #2   (View Single Post)  
Old 3rd May 2008
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,318
Default

Quote:
Originally Posted by 18Googol2 View Post
...can anyone gives me a simple example how to use those functions please.
http://www2.sys-con.com/itsg/virtual...lly/index.html
Reply With Quote
  #3   (View Single Post)  
Old 3rd May 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Default

Thanks occicat.

My program is TCP oriented and the following example is for UDP:

Code:
private int getSequenceNumber( DatagramPacket packet )   
 {   
  // Create a byte input stream to read the data  
  ByteArrayInputStream bin = new ByteArrayInputStream (packet.getData());  

  // Create a datainput stream to read sequence number  
  DataInputStream din = new DataInputStream (bin);  

  int sequenceNumber;  

  try  
  {   
   sequenceNumber = din.readInt();  
  }   
  catch (IOException ioe)  
  {   
   sequenceNumber = 0;  
  }   

  return sequenceNumber;  
 }
I have spent almost an hour on google but couldnt work out how to get/set the sequence number with TCP
Reply With Quote
  #4   (View Single Post)  
Old 3rd May 2008
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,318
Default

Quote:
Originally Posted by 18Googol2 View Post
My program is TCP oriented...
Sorry, you will have to do the translation of Spanish, Portuguese, or whatever the language is yourself. Google Translator may be of use.

http://www.koders.com/java/fid4D5D83...C39E58967.aspx
Reply With Quote
Reply

Tags
java

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
external drive partition question + fdisk question gosha OpenBSD General 15 15th June 2009 02:00 PM
apache: data stuck in socket? goertzenator FreeBSD General 8 16th February 2009 04:01 PM
Java and AI-programming idefix Programming 4 7th February 2009 01:41 PM
Socket A Semprons Sonya General Hardware 7 17th January 2009 04:32 AM
Installing java question neurosis FreeBSD Ports and Packages 3 22nd July 2008 02:42 AM


All times are GMT. The time now is 10:29 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick