Socket programming
I am designi开发者_运维技巧ng an application using sockets to connect to each other over the network. Now to test these modules I have to run both of them on separate computers. I want to test them on two laptops. Can I run them on separate laptops connected with just a normal crossover cable or do I need a more conventional network with switch?
Actually, you don't need two computers for this. We do this sort of stuff regularly using virtual machines and it's been a lot easier than trying to source extra hardware.
Don't get me wrong, you can connect two ethernet ports directly using a crossover cable (I think from memory, only the transmit and receive pairs need to be swapped but it's been a while so I can't be certain).
But I've found the virtual machine solution is at least as easy and also gives you added advantages such as backout points if, for some reason, your VMs get damaged somehow, which happens quite a bit during development.
Being able to restore to a baseline configuration just be copying some files is a lot easier than re-installing everything from scratch.
So, in terms of (descending) desirability, I would rate the possibilities thus:
- two virtual machines on your development host running your software (memory permitting).
- a crossover cable connecting your two laptops directly.
- a hub.
- a switch.
The reason I prefer a hub over a switch is because it's less complicated and usually cheaper (see here for some extra info). A switch tends to have internal state to better manage collisions whereas a hub is more like a means to just tie all the cables together. Neither of those will be cheaper than a crossover cable which in turn will almost certainly cost more than VMWare Player and its brethren.
精彩评论