Minimising client processing - c socket programming -
i working on client/server model based on berkeley sockets , have finished i'm stuck way know of data has been received whilst minimising processing being executed on client side.
the client working has little memory , battery , deployed in remote conditions. means wherever possible trying avoid processing (and therefore battery loss) on client side. following conditions on client outside of control:
the client sends data 1056 bytes @ time until has ran out of data send (i have no idea number 1056 came if think know interested)
the client unpredictable in when send data (it attached wild animal , sends data determined connection strength , battery life)
the client has unknown amount of data send @ given time
the data transmitted though grsm enabled phone tag (not sure relevant i'm assuming information help)
(i emulating data expecting receive client through localhost, if seems work ask company interning invest in static ip address allow "real" tcp transfers, if doesn't won't. don't think relevant but, again, rather provide information little)
at moment using while loop , incrementing number of bytes received in order "recv()" each of 1056 byte sections. problem server needs receive unknown number of these. me, obvious solutions send number of sections received in initial header client or mark last section being sent in way. however, both of these approaches require processing on client side, wondering if there way check whether client has closed socket server side? or whether closing connection server after pre-determined period of time without information client feasible? if these aren't possible love hear other suggestions.
tldr: condition can use here minimise client-side processing?
while(!(/* client has ran out of data send*/)) { receive1056section(); }
also, know bad practise make stackoverflow account , ask question, didn't know else do, i'm sorry. please don't hesitate mean if i've missed obvious.
here suggestion how interaction:
the client:
client connects server via tcp.
client sends chunks of data until data has been sent. flush send buffer after each chunk.
when done client issues shutdown
on socket, sleep
s couple of seconds , closes connection.
the client sleeps until next transmission. if transmission unsuccessful, sleep time should shorter prevent unsent data overflow avaiable memory.
if client unable connect extended period of time, have discard data doesn't fit in memory.
i assuming sleep
reduces power consumption.
the server:
the server programcan single-threaded unless need massive scalability. listening incoming connections on agreed port.
whenever client connects, new socket created.
use select()
see sockets has data (don't forget include listening socket!), , non-blocking reads read sockets.
when appropriate error (no more data read , other side has shutdown
it's side of connection), can close socket.
this should work fine couple of thousand simultaneous connections.
Comments
Post a Comment