By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

writing to a socket with data from struct

P: n/a
I am trying to write a small program that sends some data over the
network to a server. The data I want to send is read from the command
line i.e. dms 2 somedata otherdata value hostname port. I have the
client talking to the server. The problem I am having sending the
command data to the server. CreateDSM creates the network connection
to the server. This is what I am doing:

int A, B,dsm1, dsm2;
struct fullpacket {
int requesttype;
char varname;
int vartype;
char varval;
} packet;

main(int argc, char *argv[])
{
dsm1=CreateDSM(argv[5], argv[6]);
newVar(dsm1, argv[2], argv[3], argv[4]);
exit(0);
}

int newVar(const char *varname, const char *vartype, const char
*initialvalue)
{ packet.requesttype=1;
packet.varname=*varname;
packet.vartype=*vartype;
packet.varval=*initialvalue;
(void) write(dsm1, packet, sizeof(packet));
}
As you can see I am trying to write a struct to a socket. When I
compile I get the following message: incompatible type for argument 2
of 'write'. How can I fix it or get around this problem?

Thanks,
Mike

Apr 14 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
bo******@hotmail.com wrote:

int A, B,dsm1, dsm2;
struct fullpacket {
int requesttype;
char varname;
int vartype;
char varval;
} packet; (void) write(dsm1, packet, sizeof(packet));
}
As you can see I am trying to write a struct to a socket. When I
compile I get the following message: incompatible type for argument 2
of 'write'. How can I fix it or get around this problem?

There is no write() function in standard C, the topic of this
newsgroup.

<OT>

write() usually takes a pointer for the second argument, you are
passing a struct. Possibly you wanted

write(dsm1, &packet, . . . )

</OT>
Further questions should directed to a platform-specific newsgroup.


Brian
Apr 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.