I am developing a client server socket application for which I want to simulate the packet data transfer.I want a simulator which simulates the dropped packets data, message statuses, calculating packet checksum etc. Is it possible to simulate a TCP layer? If possible please provide me some links. Thanks in advance.
-
9What excactly do you like to simulate? Almost every system has simulation TCPIP network ( loopback )Konstantin Pribluda– Konstantin Pribluda2012-10-10 07:55:02 +00:00Commented Oct 10, 2012 at 7:55
-
BTW You only have streams for TCP in Java. You have no awareness of underlying packets, nor should you.Peter Lawrey– Peter Lawrey2012-10-10 08:02:18 +00:00Commented Oct 10, 2012 at 8:02
-
1@PeterLawrey Perhaps he wants a very robust simulator that gives him the ability to test things like latency, dropped packets, overall speed, etc.CrazyCasta– CrazyCasta2012-10-10 08:03:43 +00:00Commented Oct 10, 2012 at 8:03
-
I have looked and software and hardware WAN simulation and only the hardware simulators have been realistic and useful for testing.Peter Lawrey– Peter Lawrey2012-10-10 08:07:30 +00:00Commented Oct 10, 2012 at 8:07
-
1@Rocky You should edit your question and add such details (specify exactly what you want the simulator to be able to do). As the question stands it is hard to understand that this is what you're asking for.CrazyCasta– CrazyCasta2012-10-10 08:58:39 +00:00Commented Oct 10, 2012 at 8:58
|
Show 4 more comments
1 Answer
If you want to test it on a machine by itself, use 127.0.0.1 or localhost as the address you connect to. Your socket will then connect to whatever is listening to that port on your local computer (presumably your test server).
If you want to avoid TCP entirely for some reason and only use the streaming aspect of TCP you could replace the input and output streams by PipedInputStream and PipedOutputStream:
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream(pis);
// Use pis and pos in place of sock.getInputStream() and sock.getOutputStream().
4 Comments
user207421
Piped streams do not 'use the streaming aspect of TCP' at all, and they aren't an acceptable substitute for TCP streams because of their intrinsic deadlock problem. Not that 'avoid[in]g TCP' by 'only us[ing] the streaming aspect of TCP' ever made sense in the first place.
CrazyCasta
@EJP I'm assuming that the server and client are going to be running on separate threads, communicating only via the piped streams, thereby not running into a deadlock problem. By "only use the streaming aspect of TCP" I was referring to not using
sendUrgentData().user207421
It remains a contradiction in terms. Perhaps you could clarify your answer. BTW urgent data is only delivered in-band in Java so it isn't really non-streaming.
CrazyCasta
@EJP Well, a TCP connection is basically a pair of streams connecting two sockets plus an out of band channel. Since, as you point out, Java doesn't really support out of band (throwing it in the same stream is just wrong) it might as well be a pair of streams (so you would need to duplicate the code that I have above to make the other half of the connection). The testing platform would have to make the server and the client share a process (on separate threads of course). Also it would skip a lot of stuff like connection, but at a Unit test level it might be appropriate in some edge case.