Know your ISP.

User #126572   1030 posts
Whirlpool Enthusiast

Hi guys. I couldnt find anything really helpful on google how to set the sequence number. Im quite new to Java and all the source code I found are a bit too hard to understand.

In my program, the client sends a number of packets in a row. Each packet will be assigned with a sequence number. At the server, it will check the sequence number, if there is a packet out of order, it will send a NACK, asks the client to resend all the packets.

Here is what I have done with the client:


for (i = 1; i < 6; i++)
{
System.out.print("==> Message: ");
inputTxt = stdIn.readLine(); // Read from user input
out.println(i + ": " + inputTxt); // send packet to the server
System.out.println("==> Sending packet...Sent!" + '\n');
out.setSequenceNumber(i); // Assign the sequence number???
out.flush();
}


Obviously the statement:

out.setSequenceNumber(i);

is wrong and the compiler will complain, but Im clueless how to set the sequence number.

Any help is much appreciated.

posted 2008-May-14, 5pm AEST
User #44690   11103 posts
Whirlpool Forums Addict

but Im clueless how to set the sequence number.

What kind of sequence number are you talking about? Does your protocol even have a sequence number?

If you're using a reliable, ordered transport protocol, do you even need an application-level sequence number?

posted 2008-May-14, 5pm AEST
edited 2008-May-14, 5pm AEST
User #126572   1030 posts
Whirlpool Enthusiast

Foonly, the sequence number is integer and not generated by the system. For the moment I just set them from 1 to 5.

Do you mean to assign the sequence number, a new protocol is a must? Can I just assign it with each packet?

I will make a protocol, but I do it later, at the moment I just wanna solve the sequence number issue.

If you're using a reliable, ordered transport protocol, do you even need an application-level sequence number?

Not sure what you mean by application-level sequence number. But yes, the transfer must be reliable and in order

posted 2008-May-14, 5pm AEST
User #44690   11103 posts
Whirlpool Forums Addict

Do you mean to assign the sequence number, a new protocol is a must? Can I just assign it with each packet?

If you need an application-level sequence number (which I very much doubt), then you need a sequence number field in your application-level protocol. How else is going to get sent?

Not sure what you mean by application-level sequence number. But yes, the transfer must be reliable and in order

Use TCP. Problem solved.

Any application-level protocol run over TCP inherits its reliability and in-order-ness.

posted 2008-May-14, 6pm AEST
edited 2008-May-14, 6pm AEST
User #126572   1030 posts
Whirlpool Enthusiast

How else is going to get sent?

Basically it just send the messages inputted from the client machine.

Any application-level protocol run over TCP inherits its reliability and in-order-ness.

I dont use UDP so I *think* Im using TCP

posted 2008-May-14, 6pm AEST
User #44690   11103 posts
Whirlpool Forums Addict

18Googol2 writes...

I dont use UDP so I *think* Im using TCP

If it's a "stream" socket -- a Socket instance -- then, yes, it's TCP.

If it's a "datagram" socket -- a DatagramSocket instance -- then you're using UDP.

posted 2008-May-14, 6pm AEST
edited 2008-May-14, 6pm AEST
User #126572   1030 posts
Whirlpool Enthusiast

If it's a "stream" socket -- a Socket instance -- then, yes, it's TCP.

Yes, stream socket.

posted 2008-May-14, 6pm AEST
User #126572   1030 posts
Whirlpool Enthusiast

Ah, I see what you mean.

The client sends a pack of 5 messages in order, but at the server, every 3 times (if i % 3 == 0), the server reorders the sequence number (on the purpose of simulating the so called "real" internet traffic) and sends a NACK to the client, then the client retransmit the previous pack of message again.

posted 2008-May-15, 12am AEST
User #44690   11103 posts
Whirlpool Forums Addict

18Googol2 writes...

The client sends a pack of 5 messages in order, but at the server, every 3 times (if i % 3 == 0), the server reorders the sequence number (on the purpose of simulating the so called "real" internet traffic) and sends a NACK to the client, then the client retransmit the previous pack of message again.

What? That's incomprehensible.

You can't "simulate" packet reordering, not from within Java at least. The stuff you read from the socket will be ordered correctly first by the OS.

As I said before, use TCP and you don't need to think about sequence numbers, ordering, reliability or whatnot in your application code. The whole purpose of TCP is to provide a reliable, ordered stream network protocol.

posted 2008-May-15, 9am AEST
User #36572   3586 posts
Whirlpool Forums Addict

Foonly writes...

As I said before, use TCP and you don't need to think about sequence numbers, ordering, reliability or whatnot in your application code. The whole purpose of TCP is to provide a reliable, ordered stream network protocol.

Exactly, to the OP - you should really carefully read the following and understand the concepts if you want to do network programming:

Internet Protocols - general overview:
en.wikipedia.org/wiki/In...t_protocol_suite

TCP:
en.wikipedia.org/wiki/Tr...Control_Protocol

UDP:
en.wikipedia.org/wiki/Us...atagram_Protocol

PS: Download and install Wireshark and examine traffic being generated by the various applications on your computer:

www.wireshark.org

posted 2008-May-15, 10am AEST
edited 2008-May-15, 10am AEST
User #126572   1030 posts
Whirlpool Enthusiast

Its not my entire program actually. Later on I need to set up another host, the server reorders the packets and forward to that host. The host will check the sequence numbers, if they are not in order, they will reply with a NACK and request the first host to retransmit packets.

But to get started, I just keep things simple, first I have to get the host and server worked, then the 2nd host will be added later on.

posted 2008-May-16, 12am AEST
User #36572   3586 posts
Whirlpool Forums Addict

18Googol2 writes...

The host will check the sequence numbers, if they are not in order, they will reply with a NACK and request the first host to retransmit packets.

Ok, we're going in circles.

First of all, is this an assignment?

Secondly, have you read the links I sent you? If you have, you'd note that TCP (implemented using the Socket class) is already a reliable protocol - ie it inherently deals with the ordering of packets and retransmission requests. You do not have access to this functionality. You could simulate packet ordering but you need to do this in the payload. And of course, you wouldn't do this for real world applications - but I guess for an assignment it's fine. However, you will not have write access to the transport layer parameters - so forget that idea.

You can also use the DatagramSocket (implements UDP protocol). UDP does not have the reliability mechanisms of TCP - it's more of a machine gun approach - packets are sent to the host and it's the host's responsibility to implement any reliability (actually, UDP is typically used when you don't care for lost packets such as in video feeds).

posted 2008-May-16, 10am AEST
User #21418   4975 posts
Whirlpool Forums Addict

This sounds almost exactly like an assignment I just did (only in C).

You're writing a server and client that must communicate reliably. Is the data that is being sent between the 2 computers passed through another computer in the middle that will 'simulate' an unreliable network (reorder, drop, corrupt etc)?

client ---- man in the middle ---- server

Or are you passing data directly between 2 computers, however you write the server program to simulate on it's own an unreliable network (how you'd get that to work I don't know).

posted 2008-May-16, 12pm AEST
User #126572   1030 posts
Whirlpool Enthusiast

Thanks guys. I worked out how to do it this morning. Its quite simple actually, just add a number at the beginning || end of the message (payload). Gotta KISS huh :P

posted 2008-May-17, 2am AEST
User #219305   56 posts
Participant

Would have to be an assignment! I think the lecturer is looking at your understanding of the transport layer and windowing.

I'd shudder if someone was thinking about writing their own proprietary stack in java for a job.

posted 2008-May-18, 7pm AEST
edited 2008-May-18, 7pm AEST
User #44690   11103 posts
Whirlpool Forums Addict

Husker writes...

Would have to be an assignment! I think the lecturer is looking at your understanding of the transport layer and windowing.

Probably. The silly thing with that, of course, is that in most cases it's not up to the application to handle all that stuff (at least on simple one-to-one connections -- application-level synchronization is very much a real issue for distributed protocols).

If the subject was really about those kinds of things, the lecturer would have enforced the use of UDP, or a lower-level protocol (but obviously not in Java).

posted 2008-May-18, 7pm AEST
edited 2008-May-18, 7pm AEST
User #219305   56 posts
Participant

Perhaps SCTP could fit the bill, problem is the industry has been very slow to adopt it.

posted 2008-May-18, 7pm AEST
User #36572   3586 posts
Whirlpool Forums Addict

.

posted 2008-May-18, 11pm AEST
edited 2008-May-18, 11pm AEST
User #30667   3915 posts
Whirlpool Forums Addict

Husker writes...

I'd shudder if someone was thinking about writing their own proprietary stack in java for a job.

I'm pretty sure you couldn't. You'd have to write it in something else and then use JNI, or something similar, to support it.

posted 2008-May-19, 7am AEST
Hosted by
WebCentral Australia
Big numbers
983,140 threads
17,338,546 posts
2,021,486 whims sent
3,114 wiki topics
230 ISPs listed
8,099 broadband plans
829 modems & routers
40,940 features filled