network help needed
Unknown W. Brackets
unknown at simplemachines.org
Wed Oct 25 07:22:42 PDT 2006
That is only discussing how to determine how much data you should read.
If you expect the data at a constant rate, and you're consuming it,
this shouldn't be a problem.
That is, if each packet is going to be one double, or 10 doubles, you
know the length. Prefixing things with the length will change nothing.
It's like putting a large sign on your car that says "CAR" just in
case you should forget what it is.
My concern was that data might sit in the operating system's socket
buffer, but this probably won't be a worry. Normally, packets are much
bigger than 4 bytes, though... but it depends on network card and router
settings, iirc.
You should be able to use one port for two-way communication. I
honestly have never used the "socketstream" and don't know of its quality.
However, what you would probably want to do is make the socket
non-blocking and use Socket.select() to check if it is ready for reading
or for writing. This way, your server side can determine if it needs to
read a stop/start command or should send data.
For stop/start commands, you may want to use a fixed size, length
prefixing, or delimiting. As the page you linked to states, you do want
to know how much to read; it makes it faster and cleaner.
As an example, HTTP/1.0 only supported Content-Length (so you had to
know the entity size before hand) and was one connection per entity.
HTTP/1.1 was a huge improvement in performance, because it uses a single
connection for multiple entities, allows for pipelining (asking for
multiple entities before receiving any), and uses length prefixing for
the entity-body if negotiated.
All that said, your program sounds like it will be dealing with so few
bytes as to not be an issue anyway.... even at 24kB/s.
Hope that helps.
-[Unknown]
>> The operating system does some buffering and etc., but so long as you're
>> sending and the client is receiving, packets will get sent between. If
>> you do experience any problems with these buffers, you could pad the data
>> or something... but I'd be surprised if you did.
>>
> Just to surprise you, I read:
> http://tangentsoft.net/wskfaq/articles/effective-tcp.html
> And it looks like I should do some length-prefixing.
>
>> If you're getting this from the eyetracker at 4 bytes per millisecond,
>> just end it as you get it. That should be fine. Or, buffer it and send
>> it every 10 milliseconds (being 40 bytes/10 milliseconds) - shouldn't
>> really matter for an intranet connection.
>>
>> -[Unknown]
>
> Hmm, I forgot about the other 5 channels in my last post :/
> So that will be 6*4 bytes per millisecond, still not a problem I think ;)
>
> The computer recieving the data also sends start/stop signals to my
> computer.
> Should I use a different port for these signals, or just use the one port
> for both way communication (won't it interfere eg. give higher latencies?)
> Should the sockettype be stream?
>
> I'm sorry for all the questions, this whole area of programming is new to
> me. I'm more into single theaded games programming :)
>
>
More information about the Digitalmars-d-learn
mailing list