LinuxQuestions.org
Visit Jeremy's Blog.
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 02-26-2004, 12:49 AM   #1
adoyee
LQ Newbie
 
Registered: Jul 2003
Posts: 16

Rep: Reputation: 0
read socket


Mesg recieved is less than sent.I put read() in a while loop,but read blocks and the program stops.

How to recieve the same mesg with server sent?
 
Old 02-26-2004, 04:05 AM   #2
doraiashok
LQ Newbie
 
Registered: Nov 2003
Posts: 19

Rep: Reputation: 0
Give a bit more information on the code.

From my current point of view, the problem could be that you haven't sent the full string.

For example if you are sending the string str, you better give the length of the string as strlen(str)+1 so as to include the '\0'

Still your question is not clear to me....
 
Old 02-26-2004, 05:54 AM   #3
krajzega
Member
 
Registered: Jan 2004
Location: Poland
Distribution: FreeBSD 5.1
Posts: 92

Rep: Reputation: 15
1. Receiving buffer can't be smaller than sending
2. As a 3rd argument of recv (or read) you should use sizeof(buf) not strlen(buf)
3. You shouldn't use MSG_OOB as a flag in recv()
And also some questions:
What kind of socket are you using?
How big is the data you are sending?
 
Old 02-26-2004, 06:06 AM   #4
doraiashok
LQ Newbie
 
Registered: Nov 2003
Posts: 19

Rep: Reputation: 0
While sending the string buf, the length of the string has to be strlen(buf) and not sizeof(buf). For reasons take a look at the code below,

Code:
char message[1000];
.....
.....
strcpy(message,"hi");
send(sockfd,message,strlen(message)+1,0); // sends 3 bytes
send(sockfd,message,sizeof(message),0); // sends 1000 bytes
If you use sizeof(message) then 1000 bytes will be sent which is unnecessary because only 3 bytes are meaning full.
 
  


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
cannot read data at server socket, though client socket sends it jacques83 Linux - Networking 0 11-15-2005 01:58 PM
unix domain socket: how to know if i use recvmsg or read Thinking Programming 3 09-23-2005 01:51 AM
C++ Socket: How to read a long maldini1010 Programming 3 02-25-2005 03:56 PM
poor java socket read performance bobwall Linux - Networking 0 01-21-2005 09:55 PM
read socket problem (proxy server related) jnusa Programming 9 11-25-2004 09:31 AM

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

All times are GMT -5. The time now is 04:17 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