C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 05-03-2008, 04:45 PM   #1
Registered User
 
Join Date: Apr 2007
Posts: 282
Why the simple Socket Snippet doesn't work?

Sender side:
Code:
int len = strlen(str);
write(sock,&len,sizeof(int));
write(sock,str,len);
Receiver Side:
Code:
int len;
read(sock,&len,sizeof(int));
char* str=(char*)malloc(len*sizeof(char));
read(sock,str,len);
meili100 is offline   Reply With Quote
Old 05-03-2008, 11:28 PM   #2
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,326
what are return values of write and read?
what does it mean - "doesn't work" - how do you check it?

PS. And this is C, why to post on C++ board?
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is offline   Reply With Quote
Old 05-05-2008, 04:57 AM   #3
Malum in se
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 3,188
maybe because write() and read() aren't part of the socket API !?

also, what OS? I don't see any of the initialization or setup functions in that snippet. without some more context information it could be anything, a bad pointer, a bad socket, unitialized socket stack, improperly installed drivers, poor feng shui, etc.
__________________
Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.
abachler is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple program won't work on a friend's comp Ouendanation C++ Programming 6 01-25-2008 08:03 PM
How come this simple 10-line code can work ?! (very interesting) meili100 C++ Programming 7 11-15-2007 01:36 AM
Novice Beginner: Simple hello world wont work hern C++ Programming 8 06-25-2005 12:16 PM
The Bludstayne Open Works License frenchfry164 A Brief History of Cprogramming.com 8 11-26-2003 11:05 AM
when to close a socket Wisefool Networking/Device Communication 5 11-02-2003 10:33 AM


All times are GMT -6. The time now is 11:32 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22