Sponsored Content
Full Discussion: write() / read() syntax
Special Forums IP Networking write() / read() syntax Post 302419433 by jim mcnamara on Friday 7th of May 2010 06:59:09 AM
Old 05-07-2010
1. use send() & recv() on sockets they are meant for that and return more meaningfull error codes.

2. the syntax for write does not include a format string like:"%d %d" - the same is true for read
example:
Code:
retval=write(newsockfd, buffer, number_bytes_to_write);
retval=read (newsockfd, buffer, number_bytes_to_read);
retval=send(sockfd, buffer, bufferlen, 0);
retval=recv(newsockfd, buffer, bufferlen, 0);

You code cannot have compiled at all. Always check the return code from system calls. The 0 (flags argument) for recv lets you do neat stuff like MSG_PEEK.
 

10 More Discussions You Might Find Interesting

1. Programming

popening for read and write

How can 'popen()' be used for reading and writing to opening pipe? If i try 'popen("prog", "rw")' and then put and get chars - it does not work. What is wrong? (1 Reply)
Discussion started by: szzz
1 Replies

2. Shell Programming and Scripting

How do I write multiple variable syntax?

I am trying to write a script that will do a sql statement. But in the sql I will have a list (1,2,3,4). How would I go about asking for the input from the user running the script, and then transferring that back into the list as say ($var1,$var2,$var3)? It would be somewhat like this: ... (1 Reply)
Discussion started by: Captain
1 Replies

3. Shell Programming and Scripting

Find all files with group read OR group write OR user write permission

I need to find all the files that have group Read or Write permission or files that have user write permission. This is what I have so far: find . -exec ls -l {} \; | awk '/-...rw..w./ {print $1 " " $3 " " $4 " " $9}' It shows me all files where group read = true, group write = true... (5 Replies)
Discussion started by: shunter63
5 Replies

4. Programming

read/write files

Hi all, I have a problem with some read/write functions. I have a .bin file which contains a lot of structures as follows: struct alumno { char id; char apellido1; char apellido2; char nombre; float nota1p; float nota2p; float notamedia; char photofilename; }; What I have... (3 Replies)
Discussion started by: Attenea
3 Replies

5. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

6. Programming

Need help about read() and write() on TCP/IP

HI I need to implement a client/server TCP application. the customer is the client and the bartender is the server. When the customer enter the Bar, client connects to the server Server should reply the client immediately. Other wise if the server is busy, it should send an update message... (10 Replies)
Discussion started by: lixiao1212
10 Replies

7. Shell Programming and Scripting

Psed syntax -- specifically the write option

EDIT: Nevermind. I found a forth kludge to get around the psed requirement! Short version: I'm trying to use the "w" flag with psed to write all substituted lines into another file. No matter how many times I read the man pages or search with Google, I can't seem to find the proper syntax... (0 Replies)
Discussion started by: CluelessPerson
0 Replies

8. Shell Programming and Scripting

ISQL syntax can't read

Hi Everyone, newbie here, please help me i can't read the code i'm confused reading this code. select c.net_svc_id, c.inst_st_dt into ${REO_RECON_USERID_LUZON_TEMP} from ${WO_INST_SITE_COMP_FIELDS} a, ${WO_INST_SITE_COMPONENTS} b, ${WO_INST} c where a.cust_ac_no = b.cust_ac_no and... (3 Replies)
Discussion started by: nikki1200
3 Replies

9. Shell Programming and Scripting

File Read and Write

I have got a file in following format: AAAAAAA BBBBBBBB CCCCCCC DDDDDDD I am trying to read this file and out put it in following format: AAAAAAA,BBBBBBB,CCCCCCC,DDDDDD Preferred method is shell or Perl. Any help appreciated. (11 Replies)
Discussion started by: Araoki
11 Replies

10. Programming

FIFO write and read

Can someone help me to write this program in C in QNX? Using the FIFO queues write a simple communication system consisting of programs write and read. The program write the parameters given strings enclosed in single quotes. These strings are written to the FIFO file. Reads the program read... (1 Reply)
Discussion started by: ebasse2
1 Replies
recv(2) 							System Calls Manual							   recv(2)

NAME
recv - Receives messages from connected sockets SYNOPSIS
#include <sys/socket.h> ssize_t recv ( int socket, void *buffer, size_t length, int flags ); [Tru64 UNIX] The following definition of the recv() function does not conform to current standards and is supported only for backward com- patibility (see standards(5)): #include <sys/socket.h> int recv ( int socket, char *buffer, int length, int flags ); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: recv(): XNS5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the socket descriptor. Points to a buffer where the message should be placed. Specifies the size of the buffer pointed to by the buffer parameter. Points to a value controlling the message reception. The flags parameter is formed by logically ORing one or more of the following values, defined in the sys/socket.h file: Peek at incoming message. The data is treated as unread and the next recv() function (or similar function) will still return this data. Process out-of-band data. Requests that the function block wait until the full amount of data requested can be returned. The function may return a smaller amount of data if a signal is caught, the connection is terminated, or an error is pending for the socket. DESCRIPTION
The recv() function receives messages from a connected socket. The recvfrom() and recvmsg() functions receive messages from both connected and unconnected sockets; however, they are usually used for unconnected sockets only. The recv() function returns the length of the message. If a message is too long to fit in the supplied buffer, excess bytes may be trun- cated depending on the type of socket that issued the message. If no messages are available at the socket, the recv() function waits for a message to arrive, unless the socket is nonblocking. If a socket is nonblocking, errno is set to [EWOULDBLOCK]. Use the select() function to determine when more data arrives. NOTES
[Tru64 UNIX] The recv() function is identical to the recvfrom() function with a zero-valued address_len parameter, and to the read() func- tion if no flags are used. For that reason the recv() function is disabled when 4.4BSD behavior is enabled; that is, when the _SOCK- ADDR_LEN compile-time option is defined. RETURN VALUES
Upon successful completion, the recv() function returns the length of the message in bytes. If no messages are available and the peer has closed the connection, the recv() function returns a value of 0. Otherwise, the function returns a value of -1 and sets errno to indicate the error. ERRORS
If the recv() function fails, errno may be set to one of the following values: The socket parameter is not valid. A connection was forcibly closed by a peer. The data was directed to be received into a nonexistent or protected part of the process address space. The buffer parameter is invalid. A signal interrupted the recv() function before any data was available. The MSG_OOB flag is set and no out- of-band data is available. An I/O error occurred while reading from or writing to the file system. Insufficient resources were available in the system to complete the call. The system did not have sufficient memory to fulfill the request. The available STREAMS resources were insufficient for the operation to complete. Receive is attempted on a connection-oriented socket that is not connected. The socket parameter refers to a file, not a socket. The specified flags are not supported for this socket type or protocol. The connection timed out during connection establishment or due to a transmission timeout on active connection. The socket is marked nonblocking, and no data is waiting to be received. RELATED INFORMATION
Functions: recvfrom(2), recvmsg(2), send(2), sendmsg(2), sendto(2), select(2), shutdown(2), socket(2), read(2), write(2) Standards: standards(5) delim off recv(2)
All times are GMT -4. The time now is 08:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy