: Oops..... I didn't noticed it... Now try this...
:
: /*This program takes the hostname of the Web server on the command line (not a URLthat is, without the
http://). It calls gethostbyname to translate the hostname into a numerical IP address and then connects a stream (TCP) socket to port 80 on that host.Web servers speak the Hypertext Transport Protocol (HTTP), so the program issues the HTTP GET command and the server responds by sending the text of the
: home page.*/
:
: #include <stdlib.h>
: #include <stdio.h>
: #include <netinet/in.h>
: #include <netdb.h>
: #include <sys/socket.h>
: #include <unistd.h>
: #include <string.h>
: /* Print the contents of the home page for the servers socket.
: Return an indication of success. */
: void get_home_page (int socket_fd)
: {
: char buffer[10000];
: ssize_t number_characters_read;
: /* Send the HTTP GET command for the home page. */
: sprintf (buffer, GET /\n);
: write (socket_fd, buffer, strlen (buffer));
: /* Read from the socket. The call to read may not
: return all the data at one time, so keep
: trying until we run out. */
: while (1) {
: number_characters_read = read (socket_fd, buffer, 10000);
: if (number_characters_read == 0)
: return;
: /* Write the data to standard output. */
: fwrite (buffer, sizeof (char), number_characters_read, stdout);
: }
: }
: int main (int argc, char* const argv[])
: {
: int socket_fd;
: struct sockaddr_in name;
: struct hostent* hostinfo;
: /* Create the socket. */
: socket_fd = socket (PF_INET, SOCK_STREAM, 0);
: /* Store the servers name in the socket address. */
: name.sin_family = AF_INET;
: /* Convert from strings to numbers. */
: hostinfo = gethostbyname (argv[1]);
: if (hostinfo == NULL)
: return 1;
: else
: name.sin_addr = *((struct in_addr *) hostinfo->h_addr);
: /* Web servers use port 80. */
: name.sin_port = htons (80);
: /* Connect to the Web server */
: if (connect (socket_fd, &name, sizeof (struct sockaddr_in)) == -1) {
: perror (connect);
: return 1;
: }
: /* Retrieve the servers home page. */
: get_home_page (socket_fd);
: return 0;
: }
:
Hi
you did not understand me Jhon, I have a tcoserver and tcpclient programms, my application is "MATRIX MULTIPLICATION",when I send teh data to the client, it recieves the first 12287 number as I sent it,but after that the client recieves zeroes "0".
NOTE
In the first two times I run the programms,it's successed.after that once successed and once not.I never understood that.
this is the part of boat programms tcpserver and tcpclient :
tcpserver:
for(i=0;i<RAW;i++)
for(j=0;j<COL;j++)
c[i][j]=0;
printf("the result is as follows : \n\n");
//send(new_socket,buffer,bufsize,0);
for(i=(RAW/2);i<RAW;i++)
for(j=0;j<COL;j++)
{ //printf("the result is as follows : \n\n");
while(d<(RAW/2))
{ //printf("the result is as follows 10: \n\n");
for(y=0;y<COL;y++)
{
buffer[t]=a[d][y];
//printf("buffer[%d]=%d\t",t,buffer[t]);
t++;
}
d++;
}
if(d==(RAW/2))
{
for(q=0;q<RAW;q++)
for(y=0;y<COL;y++)
{
buffer[t]=b[q][y];
//printf("buffer[%d]=%d\t",t,buffer[t]);
t++;
}
//asd=gettimeofday(&tp, NULL);
//t1=(double)tp.tv_sec+(1.e-6)*tp.tv_usec;
//time(&s);
// printf("the result is as follows : \n\n");
send(new_socket,buffer,bufsize,0);
d++;
}
for(k=0;k<RAW;k++)
c[i][j]+=a[i][k]*b[k][j];
}
t=0;
recv(new_socket,buffer,bufsize,0);
for(i=0;i<(RAW/2);i++)
for( j=0;j<COL;j++)
{
c[i][j]=buffer[t];
t++;
}
for(i=0;i<RAW;i++)
for(j=0;j<COL;j++)
printf("c[%d][%d]=%d\t",i,j,c[i][j]);
//time(&f);
//asd=gettimeofday(&tp, NULL);
//t2=(double)tp.tv_sec+(1.e-6)*tp.tv_usec;
//temp=t2-t1;
/*printf("\n\n%s\n", ctime(&s));
printf("%s\n", ctime(&f));
printf("%f in sec , %f in sec:usec\n", difftime(f, s),temp);
*/
free(buffer);
close(new_socket);
close(create_socket);
tcpclient:
for(j=0;j<COL;j++)
{
a[i][j]=0;
b[i][j]=-1;
c[i][j]=0;
}
//printf("the result is as follows 1: \n\n");
recv(create_socket,buffer,bufsize,0);
for(i=0;i<(RAW/2);i++)
for(j=0;j<COL;j++)
{
// printf("buffer[%d]=%d\t",t,buffer[t]);
a[i][j]=buffer[t];
t++;
}
for(i=0;i<RAW;i++)
for(j=0;j<COL;j++)
{
b[i][j]=buffer[t];
printf("b[%d][%d]=%d\t",i,j,b[i][j]);
t++;
}
t=0;
for(i=0;i<(RAW/2);i++)
for(j=0;j<COL;j++)
{
for(k=0;k<RAW;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
//printf("c[%d][%d]=%d\t",i,j,c[i][j]);
buffer[t]=c[i][j];
t++;
}
send(create_socket,buffer,bufsize,0);
printf("\nThe message has been sent to the server.\n");
//}while (strcmp(buffer,"/q"));
free(buffer);
close(create_socket);