Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate p2p network traffic on a single computer

What is the best way to simulate a network in Java?

I'm in the early stages of a networked peer to peer project, and to determine some of the required characteristics of the clients I'd like to be able to simulate 100+ instances concurrently on my PC.

Ideally I'd like to create a "simulation" version of the sockets, with their own inputs and output streams. Eventually, I'm going to use these streams for data transfer instead of just moving data around between java objects, so what I'm wanting to simulate is the kind of latency, data loss and other errors you might get in an actual network.

Ideally these simulation methods would be very close to the actual stream standards of java.net.*, so I wouldn't need to do much of a rewrite in order to move from simulation to the actual client.

Can anyone point me in the right direction?

like image 235
N. McA. Avatar asked May 11 '13 11:05

N. McA.


2 Answers

You can use Akka to create millions of Actors on a single machine, then organize communication between them similar to 'real' network.

Here's an example project: https://github.com/adelbertc/scalanet

like image 125
vitalii Avatar answered Oct 10 '22 02:10

vitalii


Well you don't really need to use any tools but put your brains to design it better.

You need interfaces for the under lying communication framework.

All you need is to mock/substitute the real implementation with a dummy one once you have coded against the interfaces.This dummy implementation can introduce features like latency,dummy data etc.

You can go with spring container.You can write some dummy server sockets in the container to simulate conversations between multiple instances or better use a web container to take that headache away from you.

like image 44
Rohitdev Avatar answered Oct 10 '22 01:10

Rohitdev