Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
814 views
in Technique[技术] by (71.8m points)

c++ - Errors using same port on different machines

I have written an application ( called M2 ) which reads data arriving on one port, processes it, then sends the results out to another port.

If I choose to send data to 193.168.1.101:5001 everything works.

If I send to 192.168.1.101:5001 it does not. Why should changing the first byte of the IP address make any difference?

The reason for the change is that when I trasmit a packet to 193.168.1.101:5001 then it takes about a millisecond, but when I transmit to 192.168.1.101:5001 it takes over a second. This thousand-fold change in timing messes up everything else in my program - in particular reader starvation sets in and I start losing input packets.

What would cause such a drastic change in transmission time? Note that the transmission does not fail, it just takes an extremely long time.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The address 192.168.1.101:5001 is extremely slow ( around 2 seconds to transmit a packet ) compared to 193.168.1.101:5001 ( about 1 millisecond ). Since the transmitter was using synchronous sends, the input was starved of CPU and so input packets were dropped.

I changed the the output transmitter to asynchronous operation, with a deadline timer to limit the amount of time spent on attempting to transmit a packet. This solved the input starvation. I used code based on this: http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/example/timeouts/blocking_udp_client.cpp

I am still curious why one address would be a thousand times slower than another. The bad address is on the same subnet ( is that the correct term? ) as the transmitting computer, so perhaps that has something to do with it?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...