Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Simulate Latency

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Simulate Latency

    Hi guys,

    Is it possible with Java to delay packets?

    Basically what I want to do is add X ms to every packet going out from a computer to simulate latency, eventually I would add in packet loss etc, but for now, my main concern is just adding delay to packets to increase ping.

    I've read from a few different forums where people have asked something similar, and people have said it's not possible. If so, why is it not possible?

    Thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: Simulate Latency

    add X ms to every packet going out from a computer to simulate latency
    You could use Thread.sleep(X) to delay the sending of a packet.

  3. The Following User Says Thank You to Norm For This Useful Post:

    pixelDepth (November 30th, 2011)

  4. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Simulate Latency

    Hi Norm,

    Thanks for the reply.

    I probably should have included that I am completely new to networking in Java, in fact I'm rather new to Java, but want to jump straight in.

    Basically I am doing something to do with lag compensation for gaming (basically a report on the effects of it, and how people with good connections are getting penalised), basically I bridge my console connection to my computer, and then I can see all network traffic (via wireshark), I then want to add latency to the packets. I can already do this via Linux, by using netem, however I wanted to improve my Java knowledge and get into a little bit of networking, so want to attempt to do something similar just for the sake of learning.

    Is this still possible? If so, where do I start. Am not after any code (samples would help though ), just somewhere to start reading (maybe even a good book?).

    Sorry if I wasn't clear in my first post.

    Thanks

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,154
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: Simulate Latency

    My suggestion assumed that you had a java program that was sending packets.
    Your setup doesn't sound like that is what you are doing. I don't see where you have any java code in what you are doing.

  6. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Simulate Latency

    Yeah as you are more concerned with Networking, so i will recommend you to seeTrail: Custom Networking (The Java™ Tutorials)

  7. The Following User Says Thank You to Mr.777 For This Useful Post:

    pixelDepth (November 30th, 2011)

  8. #6
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Simulate Latency

    Quote Originally Posted by Norm View Post
    My suggestion assumed that you had a java program that was sending packets.
    Your setup doesn't sound like that is what you are doing. I don't see where you have any java code in what you are doing.
    I think basically I want to do something like Wireshark (wireshark.org), but not so complicated in the sense of analysing the packets. I want to write a Java app to capture all packets, add a delay, then let the packets go on their way.

    There is software out there that already does it, but want to try writing my own. Am unsure how they are doing it.

  9. #7
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Simulate Latency

    Quote Originally Posted by Mr.777 View Post
    Yeah as you are more concerned with Networking, so i will recommend you to seeTrail: Custom Networking (The Java™ Tutorials)
    Thanks, will have a read of that

Similar Threads

  1. Class that will simulate a book catalog system
    By fatika26 in forum Object Oriented Programming
    Replies: 4
    Last Post: November 17th, 2011, 07:34 AM
  2. Audio capture (TargetDataLine) latency
    By Pikkurotta in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: April 14th, 2011, 04:20 PM

Tags for this Thread