Hi I am Trying to use the following code to send TCP data and listening using 
netcat.I don't receive anything.But it works in the simulator.The device works 
with UDP.I am using the Garmin IQue 3600.Please let me know if u see any 
obvious problems.A connection is opened but no data is  sent In tcp mode, my 
application being near real time will benefit from UDP but I would also like 
tcp to work.

static void SendTCP(void)
{
   Err error;
   UInt16 AppNetRefnum;
   UInt16 ifErrs;
   NetSocketRef socket;
   Int16 result;
   NetSocketAddrINType destAddr;

   char buf[bufLen] = "TCP o NetLib!\n";
   UInt16 sentBytes = 0;

   ClearResults();
   /*Move data from buffer to buf*/
   MemMove(buf,buffer,bufLen);
   // Find the network library
   ShowResult(MainSysLibFindResultLabel, PROCESSING_RESULT);
   error = SysLibFind("Net.lib", &AppNetRefnum);
   ShowResult(MainSysLibFindResultLabel, error);
   if (error) return;

   // Get and validate the destination
   if (!GetAddr(AppNetRefnum, &gPrefs.addr, &gPrefs.port)) {
      FrmAlert(InvalidDestAlert);
      return;
   }

   // Open the network library
   ShowResult(MainNetLibOpenResultLabel, PROCESSING_RESULT);
   ShowResult(MainNetLibOpenIFResultLabel, PROCESSING_RESULT);
   error = NetLibOpen(AppNetRefnum, &ifErrs);
   ShowResult(MainNetLibOpenResultLabel, error);
   ShowResult(MainNetLibOpenIFResultLabel, ifErrs);
   if (ifErrs || (error && error != netErrAlreadyOpen)) goto CloseNetLib;

   // Open a socket
   ShowResult(MainNetLibSocketOpenResultLabel, PROCESSING_RESULT);
   socket = NetLibSocketOpen(AppNetRefnum,        // Network library
                             netSocketAddrINET,   // Address domain
                             netSocketTypeStream, // Socket type
                             netSocketProtoIPTCP, // Protocol
                             -1,                  // Timeout
                             &error               // Error result
                             );
   ShowResult(MainNetLibSocketOpenResultLabel, error);
   if (error) goto CloseNetLib;

   // Connect the socket to its destination
   MemSet(&destAddr, sizeof(destAddr), 0);
   destAddr.family = netSocketAddrINET; // This should match the second 
argument to NetLibSocketOpen
   destAddr.port = gPrefs.port;
   destAddr.addr = gPrefs.addr;
   error = 0;
   ShowResult(MainNetLibSocketConnectResultLabel, PROCESSING_RESULT);
   result = NetLibSocketConnect(AppNetRefnum,                  // Network 
library
                                socket,                        // Socket 
reference
                                (NetSocketAddrType*)&destAddr, // Destination 
address
                                sizeof(destAddr),              // Length of 
destAddr
                                -1,                            // Timeout
                                &error                         // Error result
                                );
   if (result == -1) {
      ShowResult(MainNetLibSocketConnectResultLabel, error);
      goto CloseSocket;
   } else {
      ShowResult(MainNetLibSocketConnectResultLabel, 0);
   }

   // Send data
   ShowResult(MainBytesSentResultLabel, PROCESSING_RESULT);
   while (sentBytes < bufLen) {
      ShowResult(MainNetLibSendResultLabel, PROCESSING_RESULT);
      result = NetLibSend (AppNetRefnum,       // Network library
                           socket,             // Socket reference
                           buf + sentBytes,    // Buffer to send
                           bufLen - sentBytes, // Bytes to send from buffer
                           0,                  // Flags
                           NULL,               // Destination address -- does 
not apply to TCP sockets
                           0,                  // Length of destination address
                           -1,                 // Timeout
                           &error              // Error result
                           );
      if (result == -1) {
         ShowResult(MainNetLibSendResultLabel, error);
         goto CloseSocket;
      }
      sentBytes += result;
      ShowResult(MainBytesSentResultLabel, sentBytes);
   }
   ShowResult(MainNetLibSendResultLabel, 0);

   // Close the socket
   CloseSocket:
   ShowResult(MainNetLibSocketCloseResultLabel, PROCESSING_RESULT);
   result = NetLibSocketClose (AppNetRefnum, // Network Library
                               socket,       // Socket reference
                               -1,           // Timeout
                               &error        // Error result
                               );
   if (result == -1) {
      ShowResult(MainNetLibSocketCloseResultLabel, error);
   } else {
      ShowResult(MainNetLibSocketCloseResultLabel, 0);
   }

   // Close the network library
   CloseNetLib:
   ShowResult(MainNetLibCloseResultLabel, PROCESSING_RESULT);
   error = NetLibClose(AppNetRefnum, false);
   ShowResult(MainNetLibCloseResultLabel, error);
}

Code borrowed from HelloNetLib

Tishampati Dhar
Software Developer

APOGEE IMAGING INTERNATIONAL
Building 12B 
1 Adelaide - Lobethal Road 
Lobethal  SA  5241 
  
Telephone:  +61 - 8 - 8389 5499
Fax:              +61 - 8 - 8389 5488
Mobile:        +61  - 421982049
Email:  [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
Web:    www.apogee.com.au <http://www.apogee.com.au>   
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
"The information in this e-mail may be confidential and/or commercially 
privileged. It is intended solely for the addressee. Access to this e-mail by 
anyone else is unauthorised. If you are not the intendedrecipient, any 
disclosure, copying, distribution or action taken or omitted to be taken in 
reliance on it, is prohibited and may be unlawful."


-- 
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to