![]() |
| | #1 |
| Registered User Join Date: Apr 2007
Posts: 282
| Why the simple Socket Snippet doesn't work? Code: int len = strlen(str); write(sock,&len,sizeof(int)); write(sock,str,len); Code: int len; read(sock,&len,sizeof(int)); char* str=(char*)malloc(len*sizeof(char)); read(sock,str,len); |
| meili100 is offline | |
| | #2 |
| CSharpener 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 | |
| | #3 |
| Malum in se 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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |