I am newbie in sockets. I am writing a clent-server application and I got the following issue.
Clent:
void * msgDispatcher(...){
...
while(isRunning){
read(rxSocket, buf, ...);
}
}
int main(...){
...
connect(txSocket, ...);
connect(rxSocket, ...);
createThread(..., msgDispatcher, ...);
while(isRunning){
fgets(buf, ...);
write(txSocket, buf, ...);
}
}
Server:
int main(...){
...
listenerSocket = socket(...);
bind(listenerSocket,...);
listen(listenerSocket, 10);
rxSocket = accept(listenerSocket, (sockaddr*) &clientAddr, &addrLength);
listen(listenerSocket, 10);
txSocket = accept(listenerSocket, (sockaddr*) &clientAddr, &addrLength);
while(isRunning){
read(rxSocket, ...);
write(txSocket, ...);
}
}
All messages that I send from the client are received on the server, but all responses from the server are not received on the client.
Server sends messages using write(txSocket, …); and there are no issues here. But client is waiting all time on the read(rxSocket, …) and there are no msgs are received.
What is incorrect in this code? How to connect/accept two sockets from one client on the server or is there the best way to do it?
Thanks
I digged some hours today and return the code as in the question. Two sockets work fine now. RxSocket on client receives all messages from the server and TxSocket sends messages to the server.
Looks like it was a typo in the code.
P.S. listen() function can be invoked only one time, but calling twice does not affect anything.