Hi
I am using recv() from socket.h in one of my TCP-client projects.
The problem is that the buffer variable in recv(socketDescriptor,
buffer, flags) points to some stray location and when the incoming
string is filled into it, there are trailing junk characters also.
The code portion refering to it is somewhat like:
int rcvStatus;
char *buffer;
rcvStatus = recv(socketDescriptor, buffer, flags);
std::cout<< buffer << std::endl;
If I initialize the buffer variable to NULL or "0", the recv() returns
-1, that is it doesn't accept the incoming string.
So, Please help me to clean the buffer variable, before it is being
filled with the incoming string.
Thanks
Aditya 4 7236
the following will work:
int len = 1024;
char buffer[1024 + 1];
len = recv(socketDescriptor, buffer, len,flags);
if (len 0){
//there is actual data received.
buffer[len] = '\0';
//process the data in buffer.
}else if (len == 0){
//the connection has closed.
}else{
//unknown error occur.
}
On 5ÔÂ29ÈÕ, ÏÂÎç12ʱ55·Ö, Aditya <adityagupta...@gmail.comwrote:
Hi
I am using recv() from socket.h in one of my TCP-client projects.
The problem is that the buffer variable in recv(socketDescriptor,
buffer, flags) points to some stray location and when the incoming
string is filled into it, there are trailing junk characters also.
The code portion refering to it is somewhat like:
int rcvStatus;
char *buffer;
rcvStatus = recv(socketDescriptor, buffer, flags);
std::cout<< buffer << std::endl;
If I initialize the buffer variable to NULL or "0", the recv() returns
-1, that is it doesn't accept the incoming string.
So, Please help me to clean the buffer variable, before it is being
filled with the incoming string.
Thanks
Aditya
On May 28, 9:55 pm, Aditya <adityagupta...@gmail.comwrote:
Hi
I am using recv() from socket.h in one of my TCP-client projects.
The problem is that the buffer variable in recv(socketDescriptor,
buffer, flags) points to some stray location and when the incoming
string is filled into it, there are trailing junk characters also.
The code portion refering to it is somewhat like:
int rcvStatus;
char *buffer;
rcvStatus = recv(socketDescriptor, buffer, flags);
What is the size of the buffer? Typically you should allocate a
buffer of some size either on the stack or heap and then pass this
size to recv as the 3rd arg. recv on success returns the number of
bytes received. You should then read only those many bytes from the
buffer passed to recv. Hope his helps.
std::cout<< buffer << std::endl;
If I initialize the buffer variable to NULL or "0", the recv() returns
-1, that is it doesn't accept the incoming string.
So, Please help me to clean the buffer variable, before it is being
filled with the incoming string.
Thanks
Aditya
Aditya wrote:
Hi
I am using recv() from socket.h in one of my TCP-client projects.
Please don't multi-post on Usenet, as you where told elsewhere, this
belongs on comp.unix.programmer.
--
Ian Collins.
On May 29, 10:18 am, Archie <nraut...@gmail.comwrote:
On May 28, 9:55 pm, Aditya <adityagupta...@gmail.comwrote:
Hi
I am using recv() from socket.h in one of my TCP-client projects.
The problem is that the buffer variable in recv(socketDescriptor,
buffer, flags) points to some stray location and when the incoming
string is filled into it, there are trailing junk characters also.
The code portion refering to it is somewhat like:
int rcvStatus;
char *buffer;
rcvStatus = recv(socketDescriptor, buffer, flags);
What is the size of the buffer? Typically you should allocate a
buffer of some size either on the stack or heap and then pass this
size to recv as the 3rd arg. recv on success returns the number of
bytes received. You should then read only those many bytes from the
buffer passed to recv. Hope his helps.
std::cout<< buffer << std::endl;
If I initialize the buffer variable to NULL or "0", the recv() returns
-1, that is it doesn't accept the incoming string.
So, Please help me to clean the buffer variable, before it is being
filled with the incoming string.
Thanks
Aditya- Hide quoted text -
- Show quoted text -
Hi
Thanks
That Helps.... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Wayno |
last post by:
My php logs are coming up empty. I have done all I can think of, and
all that made sense to me. Can someone take a look at my php.ini
please and tell me what you think may be the problem.
I...
|
by: tornado |
last post by:
Hi all,
I am pretty new to PHP. I was reading PHP manual and trying out the
example from 2nd
chapter (A simple Tutorial). When i try to print the variable as
given in the example it returns...
|
by: Robert A. van Ginkel |
last post by:
Hello Fellow Developer,
This looks like a long mail, but at the end of this post is my socket
wrapper attached.
I want to make a timeout procedure that starts counting down after the...
|
by: daniel.shaya |
last post by:
I'll try and keep this brief so in a nutshell:
I have large distributed java system running on a Windows 2003 server
(4cpu 8Gb memory).
Periodically the following exceptions occurs in the...
|
by: ppuniversal |
last post by:
Can anyone tell me how to flush a socket stream in C++.
I am making an Client Server application in C++ and use the send() and recv() functions. i want to flush the socket buffer as i am getting...
| |
by: Aditya |
last post by:
Hi
I am using recv() from socket.h in one of my TCP-client projects.
The problem is that the buffer variable in recv(socketDescriptor,
buffer, flags) points to some stray location and when the...
|
by: deepak nayak |
last post by:
hi,
We have Primary / Secondary Client / Server architecture. The
server is supposed to receive data from Primary client but ignore the
Secondary Client data. I have to somehow ignore the...
|
by: John Salerno |
last post by:
I wrote some pretty basic socket programming again, but I'm still confused about what's happening with the buffer_size variable. Here are the server and client programs:
--------------
from...
|
by: Giampaolo Rodola' |
last post by:
Hi,
I'd like to know if there's a way to determine which is the best
buffer size to use when you have to send() and recv() some data over
the network.
I have an FTP server application which, on...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |