02-10-2011
7,
1
Join Date: Oct 2010
Last Activity: 10 February 2011, 1:13 PM EST
Posts: 7
Thanks Given: 0
Thanked 1 Time in 1 Post
Its a client socket.
length=sizeof(clientAddr);
socketFd=createSocket("tcp");
//setting the server address
clientAddr.sin_family=AF_INET;
clientAddr.sin_addr.s_addr=INADDR_ANY;
port=port+((incrementor++)%50);
clientAddr.sin_port=htons(port);
bindSocket(socketFd,&clientAddr,length);
//setting the server address
serverAddr.sin_family=AF_INET;
serverAddr.sin_addr.s_addr=INADDR_ANY;
serverAddr.sin_port=htons(31000);
/*TCP Connection with slave*/
if((connect(socketFd,(struct sockaddr*)&serverAddr,sizeof(serverAddr)))==-1){
printf("Err in connect\n");
exit(0);
}
//request to server
if(send(socketFd,command,strlen(command)+1,0)<0){
printf("Err in Sending read request to server\n");
}
if(bytesReceived=recv(socketFd,reply,sizeof(reply),0)<0){
printf("Err in receiving reply from server\n");
}
shutdown(socketFd,2);