473,769 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket program in c++. gives "‘read’ was not declared " error on read () system call

28 New Member
Hi guys I wrote a socket program in c++ and used blocking system call read () for receiving data on socket. But it gives following error while compilation

[HTML]g++ -Wall -g -I`pwd`/../include -lpthread -c SocketDescripto r.cc -o `pwd`/../lib/SocketDescripto r.o
SocketDescripto r.cc: In member function ‘Status SocketDescripto r::Recv(int&, unsigned char*, int&)’:
SocketDescripto r.cc:79: error: ‘read’ was not declared in this scope
make: *** [SocketDescripto r.o] Error 1[/HTML]

definition of this read () call is:
int count read (int socketFd, char * buffer, int bufferlength, int flags)

When use the same call in a C programe I don't get this error. Moreover programe works fine. I think C library uses certain default headers and C++ do not.

Do anybody has any idea? Or please tell how I can look for it.


Thanks
Nov 19 '07 #1
3 12585
oler1s
671 Recognized Expert Contributor
Let's see some code.

Here's the first thought that passed into my head. You didn't include the header properly. C implicitly assumes a function returns an int. I.e., you could potentially get away with a lot of bad code, because Wall won't trap everything. C++ is more strict though.
Nov 19 '07 #2
mohammadazim
28 New Member
Following are the headers I have included in both the programs.
#include <netinet/in.h>
#include <linux/socket.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

C code:
13 memset(buff, '\0', BUFFLEN);
14 if (read(sock, buff, BUFFLEN, flags) < 0){/*error handling*/}
15 printf("[SERVER] %s", buff);

C++ code:

75 Status SocketDescripto r::Recv(Int32 & msgType, UInt8* data, Int32 & data len)
76 {
77 UInt8 *buff = new UInt8[MAX_DATA_LEN];
78 Int32 len, totallen;
79 if ( read(descriptor , buff, len, 0) < 0)
80 {
81 return ERROR;
82 }

It would be a great help if you are able resolve it. From two days I am looking for it.

Thanks
Nov 22 '07 #3
mohammadazim
28 New Member
Hi I figured it out in a way.
I added an h and c file to my code having wrappers over read and write sys calls. Compiled them with C compiler. And used the c header in the code where I needed read and write with C lang linkage specifier.
It works fine now.
Nov 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
9050
by: Johannes Eble | last post by:
Hello Python community, I am trying the echo-client and echo-server examples in Chapter 10, "Programming Python" by Mark Lutz. It is probably the most simple sockets sample: A socket server just echoing the socket clients' requests. The program works so far. I first start the server in one dos box, then the client in another dos box on my machine.
6
5488
by: Rune | last post by:
Hi, I've written a very simple 'kill-server' to help me shut down processes through Telnet or HTTP. The kill-server is a function and is launched as a thread. I use the module socket.py on Python v2.3 (Windows) I can use telnet host:port and enter the secret killword or use a broser with http://host:port/secret_killword The 'kill-server' validates the secret_killword and writes a file
0
1764
by: Ajay | last post by:
hi! my application is throwing a bad socket error raise error(EBADF, 'Bad file descriptor') socket.error: (9, 'Bad file descriptor') basically i have the following interchange application service <server1> <client1>
3
13916
by: Magnus Lycka | last post by:
I have a socket server like below which I want to exit when it's out of data. If I interrupt the client, I'll get a broken pipe on the server side, and after a Ctrl-C, I can restart the server again, but if I let it run out of data, and exit via handle_error as can be seen below, I will get a socket.error: (98, 'Address already in use') when I try to restart the server. (Unless I wait a minute or so, or use another port.) I feel like I'm...
3
3709
by: Billism | last post by:
My email client (I programmed) recently has stopped being able to send email with my XP machine. I have had 3 other friends test it and the same thing happens. The program has not changed, but Windows XP has. My program can connect to any other port (that I've tried) on a remote machine. However, when trying to connect to port 25 (SMTP), immediately, socket error 10053 occurs, and the socket fails to connect because of it. The problem is...
2
5021
by: Rookie | last post by:
Hi, I was writing a simple program using sockets. The program is supposed to be a TCP server that receives a string sent by the client. For this purpose I defined a char array called readString which was initially defined as readString. The program worked fine. I then increased the array size to readString and the accept socket call started giving an error (errno=14;EFAULT). This gave me the impression that the clientAddr structure was...
0
2114
by: Tomasz Naumowicz | last post by:
Hello Everybody, I have the following problem with Socket: Socket.Available reports data in the buffer (e.g. 1849 bytes) but I can't read it because Socket.Read throws an exception The exception ist being thrown because the connection is already closed. How could I read the data from the buffer? background information: I open multiple connections to my Windows 2003 Web Server (simple HTTP GET).
1
3038
by: niceyama | last post by:
Dear c.l.p, I have recently been doing the tutorial of Python and everything is well, i'm upto the pass section. Anyway, when I try to launch idle now I get the error message: Socket Error: Connection Refused. I do not have a firewall, so I don't know what is going on. Also, this comes up after it: IDLE's subprocess didn't make the connection. Either IDLE can't start a subprocess or personal firewall software is blocking the...
1
23087
by: Sergey Kozyrev | last post by:
Hi all, I'm trying to test my rulecore program with Event Generator but when I generate new event, I got error message: "Socket error: Connection refused, error code 10061". What can it be? It's rather urgent for me so I would appreciate any help Thanks in advance, Sergey
3
2453
by: W. Watson | last post by:
After simply trying to write a program with help(MakeQTE), a module, and having it fail with socket errors, I decided to restart IDLE, thinking I knew the cause. I'm now getting msgs like: "IDLE's subprocess didn't make connection. ... firewall may be blocking the connection." I doubt the FW connection. There's a small X warning dialog that says "Socket Error: Connection refused." Is there a way to reset IDLE? -- Wayne Watson (Nevada...
0
9589
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7410
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5307
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.