开发者

How to simulate Network situation where message lost or server don't send it?

开发者 https://www.devze.com 2023-03-07 11:51 出处:网络
I\'ve wrote simple Client-Server application and try to test it. I need to write some code to handle when the reply message (sent by server) is being lost and don\'t reach the client ...

I've wrote simple Client-Server application and try to test it.

I need to write some code to handle when the reply message (sent by server) is being lost and don't reach the client ...

I need to know how to simulate such situation. but I cannot.

I've tried the 开发者_C百科CTRL-C the server .. but not sure if this a good scenario.. I got from the client:

send:
0 0 0 5 0 0 1 48 25 112 -55 106 0 0 0 34 60 -72 117 -101 37 28 116 -85 -91 61 55
 -126 -50 9 5 64 -87 126 -31 -62 30 13 -90 -72 -124 118 20 88 -80 -9 -36 -33 -38
 123

java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(Unknown Source)
        at net.Net.readMessageObject(Net.java:36)
        at net.Pitcher.run(Pitcher.java:59)
        at net.Pitcher.main(Pitcher.java:122)

BTW, the app written in Java.


If your application is rather simple you can use a programm like netcat to connect to it, dont send anything at some point and see what happens. Otherwise what you could do is rewrite your server app a little bit to introduce some sort of random fails for testing.


Create a mock network object, so you can simulate various situations, in each case manipulating the mock network object so that you can test that your application interacts with it appropriately.

0

精彩评论

暂无评论...
验证码 换一张
取 消