Sponsored Content
Full Discussion: write() / read() syntax
Special Forums IP Networking write() / read() syntax Post 302419581 by Corona688 on Friday 7th of May 2010 02:17:57 PM
Old 05-07-2010
The send buffer is an address to memory of any type. send() doesn't really care whether you feed it a pointer to a string or an integer or structure or anything else, memory's memory as far as it's concerned. It just dumps it to the socket raw. Which means you need to order it the way your receiver expects yourself before you call send() at all.

Are you trying to send ASCII text, or binary data? If you want to send it as ASCII text, you'll need to convert it:

Code:
char buf[128];
int len=sprintf(buf, "%d %d", val1, val2);
send(sock, buf, len, 0);

If you want to send it as raw binary, that's simple too:

Code:
int val1, val2;
int val1_net=htonl(val1), val2_net=htonl(val2);

send(sock, &val1_net, sizeof(val1_net), 0);
send(sock, &val2_net, sizeof(val2_net), 0);


Last edited by Corona688; 05-07-2010 at 05:27 PM.. Reason: typo
 

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
MPI_Bsend(3OpenMPI)													       MPI_Bsend(3OpenMPI)

NAME
MPI_Bsend - Basic send with user-specified buffering. SYNTAX
C Syntax #include <mpi.h> int MPI_Bsend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) Fortran Syntax INCLUDE 'mpif.h' MPI_BSEND(BUF, COUNT,DATATYPE, DEST, TAG, COMM, IERROR) <type> BUF(*) INTEGER COUNT, DATATYPE, DEST, TAG, COMM, IERROR C++ Syntax #include <mpi.h> void Comm::Bsend(const void* buf, int count, const Datatype& datatype, int dest, int tag) const INPUT PARAMETERS
buf Initial address of send buffer (choice). count Number of entries in send buffer (nonnegative integer). datatype Datatype of each send buffer element (handle). dest Rank of destination (integer). tag Message tag (integer). comm Communicator (handle). OUTPUT PARAMETER
IERROR Fortran only: Error status (integer). DESCRIPTION
MPI_Bsend performs a buffered-mode, blocking send. NOTES
This send is provided as a convenience function; it allows the user to send messages without worrying about where they are buffered (because the user must have provided buffer space with MPI_Buffer_attach). In deciding how much buffer space to allocate, remember that the buffer space is not available for reuse by subsequent MPI_Bsends unless you are certain that the message has been received (not just that it should have been received). For example, this code does not allocate enough buffer space: MPI_Buffer_attach( b, n*sizeof(double) + MPI_BSEND_OVERHEAD ); for (i=0; i<m; i++) { MPI_Bsend( buf, n, MPI_DOUBLE, ... ); } because only enough buffer space is provided for a single send, and the loop may start a second MPI_Bsend before the first is done making use of the buffer. In C, you can force the messages to be delivered by MPI_Buffer_detach( &b, &n ); MPI_Buffer_attach( b, n ); (The MPI_Buffer_detach will not complete until all buffered messages are delivered.) ERRORS
Almost all MPI routines return an error value; C routines as the value of the function and Fortran routines in the last argument. C++ func- tions do not return errors. If the default error handler is set to MPI::ERRORS_THROW_EXCEPTIONS, then on error the C++ exception mechanism will be used to throw an MPI:Exception object. Before the error value is returned, the current MPI error handler is called. By default, this error handler aborts the MPI job, except for I/O function errors. The error handler may be changed with MPI_Comm_set_errhandler; the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned. Note that MPI does not guarantee that an MPI program can continue past an error. SEE ALSO
MPI_Buffer_attach MPI_Ibsend MPI_Bsend_init Open MPI 1.2 September 2006 MPI_Bsend(3OpenMPI)
All times are GMT -4. The time now is 05:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy