c - first tcp echo client cant communicate with second tcp echo client(Bad file descriptor) -


my application multiuser echo chat program. if client sends message server sends clients including client message originates. implemented in c.

server forked process each new client connection. child processes can access socket descriptor of clients stored in shared memory

when there 1 client message echoed correctly. when second client joined , sends message echoes 2 clients correctly.

when first client send message transmited first client correctly .but when tried send message second client failed error bad file descriptor

similarly every client can transmit message clients connected before , itself, cant clients connected later

how fix this?

accessing socket descriptor doesn't mean can access socket. need share sockets themselves, not descriptors.

also, results of 2 processes trying send on same tcp connection @ same time undefined. data might interleaved, example.

so design broken.

you share sockets. how platform-dependent. need use form of ipc arbitrate process can write socket. use semaphore each socket, example.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -