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?
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
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.
For simulation purposes you may want to check Omnet++, I'ts great for big scaled simulations with built in data analysis/statistics tools. Writing is similar to c++, see the tutorials it's pretty straight-forward.
Example 6 hosts network (Taken from Omnet++ tutorial)
链接地址: http://www.djcxy.com/p/71402.html上一篇: LINQ OrderBy在iOS上使用C#发生JIT错误
下一篇: 在单台计算机上模拟p2p网络流量