Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-12-2004, 11:55 AM
|
#1
|
LQ Newbie
Registered: Sep 2004
Location: Tripoli
Posts: 22
Rep:
|
using buffer in C language
Hi every body..........
I am working on Linux redhat 9,two machines running tcpserver and tcpclient programmes,I need to send about "50000" Byte of integers, the server sends them well,but the client recieves about "12287" Byte well,but it recieves the rest of numbers zeroes!!!!!!!!!!!!!!!!!,Inever understood that.
any help will be appresiated.
abdobl.
|
|
|
09-12-2004, 12:16 PM
|
#2
|
root 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,630
|
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
--jeremy
|
|
|
09-12-2004, 01:33 PM
|
#3
|
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
|
How do you know the server is sending them correctly? Some code would be helpful.
|
|
|
09-13-2004, 02:38 AM
|
#4
|
LQ Newbie
Registered: Sep 2004
Location: Tripoli
Posts: 22
Original Poster
Rep:
|
Hi....
to be sure that the server snds them correctly I use "printf", here is the code:
/* server.c */
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<sys/time.h>
#include<stddef.h>
#include<math.h>
void main()
{
int cont,create_socket,new_socket,addrlen;
int bufsize = 50000;
int *buffer = malloc(bufsize);
struct sockaddr_in address;
printf("\x1B[2J");
if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)
printf("The socket was created\n");
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(15000);
if (bind(create_socket,(struct sockaddr *)&address,sizeof(address)) == 0)
printf("Binding Socket\n");
listen(create_socket,6);
addrlen = sizeof(struct sockaddr_in);
new_socket = accept(create_socket,(struct sockaddr *)&address,&addrlen);
if (new_socket > 0){
printf("The Client %s is connected...\n",inet_ntoa(address.sin_addr));
for(cont=1;cont<5000;cont++)
printf("\x7");
}
int i,g=0,j,u,t=0,y,d=0,q,k;
for(i=0;i<bufsize;i++)
buffer[i]=5;
send(create_socket,buffer,bufsize,0);
for(i=0;i<bufsize;i++)
ptintf("buffer[%d]=%d",i,buffer[i]); //To be sure the buffer is not empty.
close(new_socket);
close(create_socket);
}
/* client.c */
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
main(int argc,char *argv[])
{
int create_socket;
int bufsize = 50000;
int *buffer = malloc(bufsize);
struct sockaddr_in address;
printf("\x1B[2J");
if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)
printf("The Socket was created\n");
address.sin_family = AF_INET;
address.sin_port = htons(15000);
inet_pton(AF_INET,argv[1],&address.sin_addr);
if (connect(create_socket,(struct sockaddr *)&address,sizeof(address)) == 0)
printf("The connection was accepted with the server %s...\n",inet_ntoa(address.sin_addr));
int x=0,d,a[RAW][COL],b[RAW][COL],c[RAW][COL],i=0,j,t=0,k,q,w;
recv(create_socket,buffer,bufsize,0);
for(i=0;i<bufsize;i++)
printf("buffer[%d]=%d\n",i,buffer[i]);
close(create_socket);
}
|
|
|
09-13-2004, 11:44 AM
|
#5
|
LQ Newbie
Registered: Jul 2004
Posts: 18
Rep:
|
Quote:
Originally posted by abdobl
Hi....
to be sure that the server snds them correctly I use "printf", here is the code:
/* server.c */
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<sys/time.h>
#include<stddef.h>
#include<math.h>
void main()
{
int cont,create_socket,new_socket,addrlen;
int bufsize = 50000;
int *buffer = malloc(bufsize);
struct sockaddr_in address;
printf("\x1B[2J");
if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)
printf("The socket was created\n");
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(15000);
if (bind(create_socket,(struct sockaddr *)&address,sizeof(address)) == 0)
printf("Binding Socket\n");
listen(create_socket,6);
addrlen = sizeof(struct sockaddr_in);
new_socket = accept(create_socket,(struct sockaddr *)&address,&addrlen);
if (new_socket > 0){
printf("The Client %s is connected...\n",inet_ntoa(address.sin_addr));
for(cont=1;cont<5000;cont++)
printf("\x7");
}
int i,g=0,j,u,t=0,y,d=0,q,k;
for(i=0;i<bufsize;i++)
buffer[i]=5;
send(create_socket,buffer,bufsize,0);
for(i=0;i<bufsize;i++)
ptintf("buffer[%d]=%d",i,buffer[i]); //To be sure the buffer is not empty.
close(new_socket);
close(create_socket);
}
/* client.c */
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
main(int argc,char *argv[])
{
int create_socket;
int bufsize = 50000;
int *buffer = malloc(bufsize);
struct sockaddr_in address;
printf("\x1B[2J");
if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)
printf("The Socket was created\n");
address.sin_family = AF_INET;
address.sin_port = htons(15000);
inet_pton(AF_INET,argv[1],&address.sin_addr);
if (connect(create_socket,(struct sockaddr *)&address,sizeof(address)) == 0)
printf("The connection was accepted with the server %s...\n",inet_ntoa(address.sin_addr));
int x=0,d,a[RAW][COL],b[RAW][COL],c[RAW][COL],i=0,j,t=0,k,q,w;
recv(create_socket,buffer,bufsize,0);
for(i=0;i<bufsize;i++)
printf("buffer[%d]=%d\n",i,buffer[i]);
close(create_socket);
}
|
I think you should send with: "send(create_socket,buffer,bufsize*sizeof(int),0);" and recv with "recv(create_socket,buffer,bufsize*sizeof(int),0);"
|
|
|
09-15-2004, 05:18 AM
|
#6
|
LQ Newbie
Registered: Sep 2004
Location: Tripoli
Posts: 22
Original Poster
Rep:
|
Hi ..................
It did not work.I did try ,but it did not work,
there some thing I wondering about.
at the first,two aor three times it works well,and two or three times it does not work,after that may be work ,may be not.I do not know what is going on.
|
|
|
09-16-2004, 05:37 AM
|
#7
|
Member
Registered: Aug 2003
Location: DMZ
Distribution: Ubuntu
Posts: 144
Rep:
|
Sniff sniff sniff
Use a sniffer to see what is sent on the wire
Sniffers:
tcpdump (cli)
ethereal (gui)
|
|
|
09-18-2004, 03:28 AM
|
#8
|
LQ Newbie
Registered: Sep 2004
Location: Tripoli
Posts: 22
Original Poster
Rep:
|
Hi......
I try to use it but when I compile the code the compile is fails,I do not know why,may be because I do not know how to use sniffers ,you want the true ,it's the first time I listen of them. can you exolain please how to use it,and where can I put the functions you gave me.
abdobl
|
|
|
09-30-2004, 02:28 PM
|
#9
|
LQ Newbie
Registered: Sep 2004
Location: Tripoli
Posts: 22
Original Poster
Rep:
|
sorry,but there is some thing I want to explaine,when I run the programms on boat machines only 361 Bytes of my transmitted data were recieved,the rest of data were zeroes{from 362 to any number}.I do not know why,
abdobl..my regards.
|
|
|
All times are GMT -5. The time now is 11:19 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|