Hello all:
The following code snippet runs on a Visor Edge with a Xircom SWE 1130
Wireless LAN module. I'm basically setting a server to listen to a socket.
Any port number I choose gets me the error "Busy socket" (Net 0x1209 =
4617).
Any ideas?

== Begin Code Snippet ==
static void ListenToTvrc(void)
{

 NetIPAddr trtIpAddress;
 NetSocketRef socketRef = NULL;
 NetSocketRef tvrcSocketRef = NULL;
 NetSocketAddrINType trtLocalAddress;
 NetSocketAddrINType tvrcRemoteAddress;
 Int16 tvrcRemoteAddressSize;
Char trtIpAddressB[20] = "192.168.0.3";
 UInt16 trtPortNum = 8202;    <== I've tried many other numbers based on the
list published by
                                                        IANA
(http://www.iana.org/assignments/port-numbers)
 Err status;
 Int32 timeout = 10 * sysTicksPerSecond;

 if (!netLibOpen)
  return;

 if ((trtIpAddress =
  NetLibAddrAToIN(
   netLibRefNum,
   trtIpAddressB)) == -1)
 {
  ErrDisplay("Failed to convert IP address");
  return;
 }
 else
 {
  trtLocalAddress.family = netSocketAddrINET;
  trtLocalAddress.port = NetHToNS(trtPortNum);
  trtLocalAddress.addr = trtIpAddress;

  // Open socket
  socketRef =
   NetLibSocketOpen(
    netLibRefNum,
    netSocketAddrINET,
    netSocketTypeStream,
    netSocketProtoIPTCP,
    timeout,
    &status
   );
  if (!status)
  {

   // Bind the socket
   if (NetLibSocketBind(
      netLibRefNum,
      socketRef,
      (NetSocketAddrType *) &trtLocalAddress,
      sizeof(trtLocalAddress),
      timeout,
      &status
     ) == -1)
    {
    // Error
    ErrAlert(status);
   }
   else
   {
    // Listen to the socket.
    if (NetLibSocketListen(
      netLibRefNum,
      socketRef,
      5, // queue lenght
      timeout,
      &status
     ) == -1)
    {
     // Error
     ErrAlert(status);  <== Here I get the 4617 (0x1209, which is
netErrSocketBusy).
    }
    else
    {
     tvrcRemoteAddressSize = sizeof(tvrcRemoteAddress);
     // Block on accepting a connection from the TVRC.
     if (NetLibSocketAccept(
       netLibRefNum,
       tvrcSocketRef,
       (NetSocketAddrType *) &tvrcRemoteAddress,
       &tvrcRemoteAddressSize,
       timeout,
       &status
      ) == -1)
     {
      // Error
      ErrAlert(status);
     }
     else
     {
      // We can read the TVRC message now.

      Char receivedMessage[100];
      Int16 bytesReceived = 0;

      bytesReceived =
       NetLibReceive(
        netLibRefNum,
        tvrcSocketRef,
        (void *) receivedMessage,
        100,
        0, // No I/O flags
        NULL,
        NULL,
        timeout,
        &status
       );
      if (bytesReceived == -1)
      {
       ErrAlert(status);
      }
      else if (bytesReceived == 0)
      {
       ErrDisplay("Socket closed by host!");
      }
     }
    }
   }

  }
 }
}




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

Reply via email to