I am aware that TCP sockets are stream based and a single write may not send all the data. Is this the case with recv as well ?
I am in process of deciding a protocol to handle communication. I wanted some tips as to handle transactions. The data sent / received would be fixed length. Hence i am toying with the idea of discarding messages on receive do not conform to a length. The data sent is less then 100 bytes , so i am not sure how many times will i encounter a scenario where the send fails to fire it in one go or receive fails to read in one go.
Any other approaches to send /receive data ?
Since multiple receives are possible (via select call) I am not sure how to handle incomplete data from two more different clients. ( perhaps via some sort of buffer created per connection)
More importantly , if i have about 2-3 sockets from which i am receiving data , is the conventional approach to block till the complete packet(i.e. message) from one is received ?
PS : These are unix domain sockets for IPC , so no flow over n/w
How much data of the request gets sent is under the control of the kernel. Usually for anything under ~1000 bytes you can send( ) and recv( ) everything in one go.
One way -
set socket to NON-BLOCKING, sample the input with MSG_PEEK.
This does not have error handling - note. msg now has what recv probably thinks is a message. Go back and recv() nbytes.
Good practice in something like this is to have your own protocol "header"
like
00098 is length of the packet including your header
DT might mean it is data. HS might mean a heartbeat. Whatever.
The last number is a sequence that goes from 000000 -> 999999, and rolls over.
This way you can keep track of separate packets. So all you would do is sample
13 bytes, and then you know how many bytes to do a full recv() on. And you would know what to expect in the data part of the packet if any.
This is the complete code. perhaps exec is closing my listen socket descriptor. The failure is on accept call with bad file descriptor.... I am not touching/closing the listen socket any where... this is driving me crazy!
If i do not reap the child processes, it is fine... with zombies though..... but if they are reaped... the listen socket goes boom!
HI
Can anyone provide me with codes for file transfer server to client or vice versa?
Also please explain how to compile those programs in ubuntu terminal as i am totally new to socket programming.
Thanks (1 Reply)
i'm doing a simple program in socket programming on c i have server that can handle 2clients in a single machine i'm running ubuntu linux so i got it work but the probelm when clients send a message the server will echo it but i cant distinguish which client send the message client 1 or client... (7 Replies)
in socket programming how can i : Create for example 3 blank files, namely: server, client, network
•Server: act as servers/provider, will receive all requests from different client
•Client: requesters
•Network: middle-layer of communication between server & client
any tips or... (6 Replies)
can we create multiple sockets in a machine with different ip addresses and all port listen to one single port ????
i hav one tool which creates virtual interface and i m using that to create multiple ip addresses in a linux machine and i use thos eip addresses to create multiple sockets and... (1 Reply)
Hello Everyone
Iam working on tcp/ip programming.with some time interval server has to send data.client has to close the connection and to open the connection between the time interval.this is the scenario
when iam closing the connection in client side the connection terminates.how to... (1 Reply)
my system is a stand alone system... i want to try doing socket porgramming..ihave heard that this is usually done during testing...
how can i do that....? (6 Replies)
Hello,
I actually try to make client-server program.
I'm using SCO OpenServer Release 5.0.0 and when I try to compile my code (by TELNET) I've got this error :
I'm just using this simple code :
and I get the same error if I use :
If someone can help me,
Thanks (2 Replies)