Hi Guys!
I return to the best forum ever, if i need help, now is the time! Need some help with understanding these code line in a simple server-client program that demonstrates what's going on. I have a general idea, but there are few command that i am not entirely sure why they are there and what EXCATLT they do! Could someone spare some time and explain these to me? Thanks. Luke
Here we go:
1. hSock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
2. result = connect(hSock,(struct sockaddr*)&adr,sizeof(addr));
3. write(hSock,buffer,nSent);
4. result = close(hSock)
5. hServerSocket=socket(AF_INET,SOCK_STREAM,IPROTO_TCP);
6. result = bind(hServerSocket,(struct sockaddr*)&Address,sizeof(Address));
7. result = listen(hServerSocket,SIZEQUEUE);
8. hSocket=accept(hServerSocket,(struct sockaddr*)&Address,&nAddressSize);
9. read(hSocket,pBuffer,SIZEBUFFER);
10. write(hSocket,pBuffer,strlen(pBuffer)+1);
11. if(close(hSocket) == ERROR) {
printf(“\nCould not close socket\n”);
return 0;
}
that's it.
Thanks a lot
I return to the best forum ever, if i need help, now is the time! Need some help with understanding these code line in a simple server-client program that demonstrates what's going on. I have a general idea, but there are few command that i am not entirely sure why they are there and what EXCATLT they do! Could someone spare some time and explain these to me? Thanks. Luke
Here we go:
1. hSock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
2. result = connect(hSock,(struct sockaddr*)&adr,sizeof(addr));
3. write(hSock,buffer,nSent);
4. result = close(hSock)
5. hServerSocket=socket(AF_INET,SOCK_STREAM,IPROTO_TCP);
6. result = bind(hServerSocket,(struct sockaddr*)&Address,sizeof(Address));
7. result = listen(hServerSocket,SIZEQUEUE);
8. hSocket=accept(hServerSocket,(struct sockaddr*)&Address,&nAddressSize);
9. read(hSocket,pBuffer,SIZEBUFFER);
10. write(hSocket,pBuffer,strlen(pBuffer)+1);
11. if(close(hSocket) == ERROR) {
printf(“\nCould not close socket\n”);
return 0;
}
that's it.
Thanks a lot