LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 09-12-2004, 11:55 AM   #1
abdobl
LQ Newbie
 
Registered: Sep 2004
Location: Tripoli
Posts: 22

Rep: Reputation: 15
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.
 
Old 09-12-2004, 12:16 PM   #2
jeremy
root
 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,602

Rep: Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

--jeremy
 
Old 09-12-2004, 01:33 PM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
How do you know the server is sending them correctly? Some code would be helpful.
 
Old 09-13-2004, 02:38 AM   #4
abdobl
LQ Newbie
 
Registered: Sep 2004
Location: Tripoli
Posts: 22

Original Poster
Rep: Reputation: 15
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);
}
 
Old 09-13-2004, 11:44 AM   #5
aiza
LQ Newbie
 
Registered: Jul 2004
Posts: 18

Rep: Reputation: 0
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);"
 
Old 09-15-2004, 05:18 AM   #6
abdobl
LQ Newbie
 
Registered: Sep 2004
Location: Tripoli
Posts: 22

Original Poster
Rep: Reputation: 15
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.
 
Old 09-16-2004, 05:37 AM   #7
gr33ndata
Member
 
Registered: Aug 2003
Location: DMZ
Distribution: Ubuntu
Posts: 144

Rep: Reputation: 15
Sniff sniff sniff
Use a sniffer to see what is sent on the wire

Sniffers:
tcpdump (cli)
ethereal (gui)
 
Old 09-18-2004, 03:28 AM   #8
abdobl
LQ Newbie
 
Registered: Sep 2004
Location: Tripoli
Posts: 22

Original Poster
Rep: Reputation: 15
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
 
Old 09-30-2004, 02:28 PM   #9
abdobl
LQ Newbie
 
Registered: Sep 2004
Location: Tripoli
Posts: 22

Original Poster
Rep: Reputation: 15
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Download buffer SDraconis Linux - Networking 2 05-16-2005 07:06 PM
no buffer space available sanjaykalrani Linux - Networking 0 02-25-2005 11:40 AM
empty buffer cynthia Programming 4 09-20-2004 10:29 AM
IO Buffer Haafiz Linux - General 1 07-14-2004 03:24 PM
What is a buffer overflow Joey.Dale Linux - Security 4 07-12-2004 05:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration