Re: General questions about Sockets

From: David Mair (mairdanot_at_not.hotmail.com)
Date: 07/23/04


Date: Fri, 23 Jul 2004 10:59:19 -0600

Sims wrote:
> Hi all,
>
> I have written a small application that sends a 512k packet to computer A
> and then waits for computer A to send a reply, (also 512k).
> I have 3 computers, (98/ME and XPpro), to test with and so far I am happy
> with the results as it does exactly what I need.
>
> I just have a few questions that hopefully you will be able to answer.
>
> The whole turn around process, (from A to B and waiting for B again), is
> about 1 second. is that too slow or is it as expected? ( I have a default
> home user network, nothing fancy).
> Is a 512k package a reasonable size unlikely to return errors? How high
> could I push it before I see the network slowing down and/or errors ?

What you describe is about 360 packets each way, a little over 1MB in
the whole round trip. That's about 8Mbps if it takes 1s. It's not
great but it's not dreadful either. I can push about 160Mbps on switched
100Base-T and the network is at saturation by that time. You should be
able to go at least as high as 30Mbps on shared 100Mbit Ethernet before
you start getting visible exponential collision rate growth (that is
based on very old information I used to use for this kind of thing).

512kB seems a lot without any response. It's also been a long time
since I reminded myself of this but you may have a Nagle challenged
design if you are using TCP. I used to read the WinSock lame list for
amusement. Given your message size I suspect you don't have a
Nagle/Delayed ACK interaction but you could confirm it with a packet
sniffer like Ethereal (free and Google should find it for you). This
would let you capture the traffic off the wire and analyse it for delays
or other problems. FWIW, I would use application layer ACKing (small
messages saying you have got some data) from the side receiving the big
message. That way there is always a small amount of traffic in the
other direction to limit the effects of delayed ACKs and RFC whatever it
is that define's Nagle's algorithm (AFAIK he doesn't like it being
called by his name).

> To ensure that there is no data loss shall I surround my data by magic
> numbers? how shall I ensure/test that there was no data loss?
> I can setup any port in my registry, but what would be the 'default' one I
> should offer my users?

I would just use TCP. Frames have a basic checksum and it provides
guaranteed delivery or failure. It used to be that you should get a
port assigned to you but there are lots of cases where no-one bothers
(I'm guilty of that too). You could just choose a high port number.
IIRC Windows has a maximum port number used for dynamic assignment,
Google could confirm it. You could play fast and loose and simply
choose a port number you like that's well above that number. I
recommend not choosing numbers that are "fun" in decimal or hex (0xBABE
for example).

> What sort of test shall I run to be really confident that I have written a
> solid piece of code?

I guess that depends on what your application does but you could just do
extended use testing and maybe throw in a few spanners like routers
(translating and not translating), Connection failure, low bandwidth
segments (10Mbit and modem if you can swing it).

> And last but not least, I am using the class CAsyncSocket, is that the best
> I can use or is there an easier/faster/more reliable way of doing things?

I've seen anecdote either way but it all seems like a subjective thing
to me. The most vehement opinions I've seen suggest that an
asynchronous socket class is truly evil. I like async sockets but I
tend not to use classes for my async implementations. Using the Google
groups page to search for CAsyncSocket may get you some useful opinion.



Relevant Pages

  • Re: Basic NAT / Firewall Question
    ... There are two basic types of NAT (Network Address Translation) which you ... NAPT simply maps port numbers to a given address. ... Your firewall will make a note from where the connection was ... with its own address and then sends this "new" packet out on its local ...
    (Security-Basics)
  • Re: Is there any thing like Bubbleip
    ... :the dynDNS, then it detects my network administrator's server address, ... There are four important forms of NAT: ... On a Statefull Packet Inspection firewall, ... Port Address Translation. ...
    (comp.security.misc)
  • Re: how to connect firewall to router
    ... >> lan side and this port is the firewall port, ... > to their intended destination based on the IP packet's network. ... > As a packet travels through various relay points, ... It becomes a map of how the destination should respond. ...
    (comp.security.firewalls)
  • Administrivia: Are you seeing portscans from source 127.0.0.1 source port 80?
    ... IP of 127.0.0.1 and source port 80. ... Infected host picks address as source address and sends Syn packet to ... TCP/IP stack receives packet, responds with reset (if there is nothing ... Network with over 10,000 of the brightest minds in information security ...
    (Incidents)
  • Increase in UDP Port Scans
    ... I have noticed the following port scans lately on my network ... I did a little digging with google, and it appears that these ports are used ...
    (Security-Basics)