Hi,
I'm trying to build a server that runs on Palm OS, the code is shown below:
UInt16 AppNetRefnum;
NetSocketRef socket;
Err error;
UInt16 ifErrs;
Int16 result;
NetSocketAddrINType destAddr;
UInt32 localHost;
UInt32 ifCreator;
UInt16 ifInstance;
UInt16 localHostLen;
Char localHostString[16];
NetSocketAddrType connectedHost;
Int16 connectedHostLen;
NetSocketRef newSocket;
UInt16 sentBytes;
int i;
FieldType * resultado;
char helloWorld[13];
// Find the network library
error = SysLibFind("Net.lib", &AppNetRefnum);
if (error) return;
// Open the network library
error = NetLibOpen(AppNetRefnum, &ifErrs);
if (ifErrs || (error && error != netErrAlreadyOpen)){
NetLibClose(AppNetRefnum, false);
return;
}
// Open a socket
socket = NetLibSocketOpen(AppNetRefnum, // Network library
netSocketAddrINET, // Address domain
netSocketTypeStream, // Socket type
netSocketProtoIPTCP, // Protocol
-1, // Timeout
&error // Error result
);
if (error){
NetLibClose(AppNetRefnum, false);
return;
}
// bind the socket to its connection source
MemSet(&destAddr, sizeof(destAddr), 0);
destAddr.family = netSocketAddrINET; // This should match the second argument
to NetLibSocketOpen
destAddr.port = NetHToNS(porta);
result = NetLibSocketBind( AppNetRefnum, // Network library
socket, // Socket reference
(NetSocketAddrType*)&destAddr, // Destination address
sizeof(destAddr), // Length of destAddr
-1, // Timeout
&error // Error result
);
if (result == -1) {
NetLibSocketClose (AppNetRefnum, // Network Library
socket, // Socket reference
-1, // Timeout
&error // Error result
);
NetLibClose(AppNetRefnum, false);
return;
}
//sets the maximum allowable length of the queue
result = NetLibSocketListen( AppNetRefnum, // Network library
socket, // Socket reference
1, // Queue len, must be 1
-1, // Timeout
&error // Error result
);
if (result == -1) {
NetLibSocketClose (AppNetRefnum, // Network Library
socket, // Socket reference
-1, // Timeout
&error // Error result
);
NetLibClose(AppNetRefnum, false);
return;
}
connectedHostLen = sizeof(connectedHost);
//listen to the port for connections
newSocket = NetLibSocketAccept( AppNetRefnum, // Network library
socket, // Socket reference
&connectedHost, // Connected Host IP
&connectedHostLen, // Len Of connectedHost
-1, // Timeout
&error // Error result
);
if (newSocket == -1) {
NetLibSocketClose (AppNetRefnum, // Network Library
socket, // Socket reference
-1, // Timeout
&error // Error result
);
NetLibClose(AppNetRefnum, false);
return;
}
When I run this code and try to connect to the server, I get the following
error:
"PalmSim.exe - Application Error
The instruction at "0x0c6f9f5a" referenced memory at "0x0c73fb98". The memory
could not be "read".
Click on OK to terminate the program
Click on CANCEL to debug the program"
I know the problem is when I call the function netLibSocketAccept, but I can't
figure out what it is. My app worked fine with the Palm OS Garnet 5.4
Simulator, but didn't worked with the Palm OS Garnet 5.2 Simulator, and I need
it to run in the 5.2 version.
Well, Does Palm OS Garnet 5.2 not support this kind of functionality?
Thanks.
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/