?
Solved

urgent: Palm OS Emulator and netlib

Posted on 2003-03-02
14
Medium Priority
?
501 Views
Last Modified: 2013-12-27
I want to do the following:

connect -> receive hello from server -> send auth to server -> receive response from server -> send goodbye to server -> disconnect

// connect: ok
NetLibSocketConnect(libRef, socket, (NetSocketAddrType*)&srvAddr, sizeof(srvAddr), SOCKET_TIMEOUT, &err);

// Receive from server: ok
NetLibReceive(libRef, socket, (void*)&inBuf, inBufLen, 0, 0, 0, SOCKET_TIMEOUT, err);

// send something to server: ok (no error)
NetLibSend(libRef, socket, (void*)&outBuf, 7, netIOFlagOutOfBand, 0, 0, SOCKET_TIMEOUT, &err);

// receive from server: netErrSocketClosedByRemote (4628)
NetLibReceive(libRef, socket, (void*)&inBuf, 6, 0, 0, 0, SOCKET_TIMEOUT, err);

For real servers, I get netErrSocketClosedByRemote for the second call of NetLibReceive. It just can be solved by changing the server to localhost (127.0.0.1).

How can I solve this problem? I am using Palm OS Emulator and my PC is connected to internet using broadband (ethernet NIC). I don't have any cradle and modem.

Is there anything that I should set for the emulator and any software needed so that I can make my program work for the real servers (i.e. not 127.0.0.1)?

Thanks.
0
Comment
Question by:Peter Kwan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +1
14 Comments
 
LVL 3

Expert Comment

by:prakash_raj
ID: 8055793
Hi,

On your emulator, right click and select Settings-->Properties..

Did you check the Redirect Netlib calls to host TCP/IP checkbox ??

Cheers,
Prakash
0
 
LVL 16

Author Comment

by:Peter Kwan
ID: 8055883
Hi Prakash,

I have already checked "Redirect netlib calls to host TCP/IP" checkbox already.

Thanks.
0
 
LVL 2

Expert Comment

by:schang
ID: 8058305
so when your server runs locally and you point it to it, it works?

can you properly ping it from the machine your emulator is running on?
0
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
LVL 16

Author Comment

by:Peter Kwan
ID: 8061985
>so when your server runs locally and you point it to it, it works?
yes. only localhost server works. If I changed to other server (real IP but not localhost), it does not work.

>can you properly ping it from the machine your emulator is running on?
the server is up, i can ping the server properly.
0
 
LVL 3

Expert Comment

by:olan75
ID: 8074235
When calling NetLibSend you should
specify 0, not netIOFlagOutOfBand
-unless you have a good reason? which one?

If that doesn't solve it...
Are you sure the server receives what you send?
If yes, how are you sure? Are you also
developing the server?


0
 
LVL 2

Expert Comment

by:schang
ID: 8074285
Have you verified, other NetLib-enabled apps work from your emulator and can hit other servers? For example, trying using some Palm Web browser on your emulator to open up www.yahoo.com...

0
 
LVL 16

Author Comment

by:Peter Kwan
ID: 8092372
to olan75,

> When calling NetLibSend you should
> specify 0, not netIOFlagOutOfBand
> -unless you have a good reason? which one?

> If that doesn't solve it...
> Are you sure the server receives what you send?
> If yes, how are you sure? Are you also
> developing the server?
chaning to 0 does not solve the problem. i am not developing the server.

to schang:
i have tried to use web browser and can goto websites, say www.icq.com.
0
 
LVL 3

Expert Comment

by:olan75
ID: 8093698
Are you saying that when the server is running
on your local machine, it works, but not
when the server is running on a remote machine?
All other things being equal?

You really need to provide more info:

What kind of server is it? What does it do?

Do you have access to the remote machine, or
are you just connecting to some machine on the net?

Is is the exact same server software (version, etc)
that is running on your local machine and on the remote?

Are you sure you're connecting to the right port number?
What port number is it?
Are you behind a firewall?

Apparently the server does not like what you sent and it
shuts down the connection.

Could you post more code:
What did you receive the first time?
How do you check what you receive?
How do you initialize your send buffer?
Please include variable declarations and
tests that are done to check return values
of your network calls.
0
 
LVL 16

Author Comment

by:Peter Kwan
ID: 8097560
>Are you saying that when the server is running
>on your local machine, it works, but not
>when the server is running on a remote machine?
>All other things being equal?
I downloaded a freeware (but not open source) program from
the net and tried to connect to ICQ server through the program using 127.0.0.1 (to track my packet).
For my program, it is ok if I connect to ICQ login server through the program, but if I connect to the server using my own program, it fails.

>You really need to provide more info:

>What kind of server is it? What does it do?
ICQ server. (Actually I tried IMAP server, and it does not work through direct connection either.)

>Do you have access to the remote machine, or
>are you just connecting to some machine on the net?
I am just connecting to some machine on the net, I have no admin rights to access it.

>Is is the exact same server software (version, etc)
>that is running on your local machine and on the remote?

>Are you sure you're connecting to the right port number?
Yes. I hard coded it.

>What port number is it?
5190

>Are you behind a firewall?
no.

>Apparently the server does not like what you sent and it
>shuts down the connection.

>Could you post more code:
>What did you receive the first time?
Welcome message. (Correct)

>How do you check what you receive?
There is documentation on the net about the protocol.

>How do you initialize your send buffer?
>Please include variable declarations and
>tests that are done to check return values
>of your network calls.

#define MAX_PACKET_LENGTH 8192
#define SOCKET_TIMEOUT sysTicksPerSecond*5
UInt8 inBuf[8192];      // incoming buffer
UInt8 outBuf[8192];      // outgoing buffer

Err Login(const Char* userUIN, const Char* password) {
      Err error = 0;
      UInt16 netIFError;
      Int16 recvBufLen = 0, sendBufLen = 0, cookieLen = 0;
      UInt8 cookie[MAX_PACKET_LENGTH];
      Char srv2Addr[16];            // second server address: currently not used
      UInt16 i;
      UInt16 prefSize, uinLen = StrLen(userUIN);

      // Open the library      
      error  = NetLibOpen(libRefNum, &netIFError);
      if (error && error != netErrAlreadyOpen)
            return ShowError("NetLibOpen", error);
      if (netIFError)
            return ShowError("NetLibOpen", netIFError);
      
      // Open the sockets
      socket1 = NetLibSocketOpen(libRefNum, netSocketAddrINET, netSocketTypeStream, NULL, SOCKET_TIMEOUT, &error);
      if (error == -1)
            return ShowError("NetLibSocketOpen", error);

      socket2 = NetLibSocketOpen(libRefNum, netSocketAddrINET, netSocketTypeStream, NULL, SOCKET_TIMEOUT, &error);
      if (error == -1)
            return ShowError("NetLibSocketOpen", error);
      
      // Connect to server 1
//      error = Connect(socket1, DEB_SERVER, ICQ_PORT);            // debug
      error = Connect(socket1, ICQ_SERVER, ICQ_PORT);            // real
      if (error)
            return error;      
      
      // receive SRV_HELLO from server 1
      if ((recvBufLen = RecvPacket(socket1, "1: Receive SRV_HELLO", &error)) < 0)
            return error;
      
      // send CLI_IDENT to server 1
      sendBufLen = FlapIdent(userUIN, password);
      if (NetLibSend(libRefNum, socket1, (void*)&outBuf, sendBufLen, 0, 0, 0, SOCKET_TIMEOUT, &error) < 0)
            return ShowError("1: Send CLI_IDENT", error);

      // receive SRV_COOKIE from server 1
      if ((recvBufLen = RecvPacket(socket1, "1: Receive SRV_COOKIE", &error)) < 0)
            return error;
      
      if (inBuf[4 + uinLen] != 0x00 || inBuf[5 + uinLen] != 0x05) {
            // invalid
            if (inBuf[4 + uinLen] == 0x00 && inBuf[5 + uinLen] == 0x08)
                  ShowError("Too many connections. Please try again later", 10001);
            else
                  FrmAlert(alertLoginFail);
            
            // Disconnect
           if (NetLibSocketShutdown(libRefNum, socket1, netSocketDirBoth, SOCKET_TIMEOUT, &error))
                return ShowError("NetLibSocketShutdown", error);
   
          if (NetLibSocketClose(libRefNum, socket1, SOCKET_TIMEOUT, &error) < 0)
                return ShowError("NetLibSocketClose", error);
                  
            return 1;
      }
      
      // Other codes not relevant

      return error;
}

// show the error
Err ShowError(const Char* desc, const Err error) {
      Char errCode[10];
      StrPrintF(errCode, "%u", error);
      FrmCustomAlert(alertError, desc, errCode, NULL);      
      return error;             
}

/* Byte string copying */
void ByteStrCopy(UInt8* dest, const UInt8* src, const UInt16 start, const UInt16 len) {
      UInt16 i;      
      for (i = 0; i < len; i++)
         dest[i] = src[start + i];
}

// receive packets
Int16 RecvPacket(NetSocketRef socket, const Char* desc, Err* error) {
      Int16 inBufferLen = 0, inBufLen = 0, retBufLen = 0;

      MemSet(inBuf, MAX_PACKET_LENGTH * sizeof(UInt8), '\0');
      // Header
      if ((inBufLen = NetLibReceive(libRefNum, socket, (void*)&inBuf, 6, 0, 0, 0, SOCKET_TIMEOUT, error)) < 0) {
            ShowError(desc, *error);
            return -1;
      }
      retBufLen = (UInt16)inBuf[4] * 256 + (UInt16)inBuf[5] + 6;  
      inBufferLen = retBufLen - 6;
      
      while (inBufferLen > 0) {
            MemSet(inBuf, MAX_PACKET_LENGTH * sizeof(UInt8), '\0');
            if (inBufferLen >= MAX_PACKET_LENGTH - 1) {
                  if ((inBufLen = NetLibReceive(libRefNum, socket, (void*)&inBuf, MAX_PACKET_LENGTH - 1, 0, 0, 0, SOCKET_TIMEOUT, error)) < 0) {
                        ShowError(desc, *error);
                        return -1;
                  }
                  inBufferLen = inBufferLen - inBufLen;
            }
            else {
                  if ((inBufLen = NetLibReceive(libRefNum, socket, (void*)&inBuf, inBufferLen, 0, 0, 0, SOCKET_TIMEOUT, error)) < 0) {
                        ShowError(desc, *error);
                        return -1;
                  }                  
                  inBufferLen = 0;
            }      
      }
      
      return retBufLen;
}

=================================


0
 
LVL 3

Accepted Solution

by:
olan75 earned 400 total points
ID: 8104574
The only thing I can think of is that you are
sending the server a packet that it does not understand
and it shuts down the connection.

Probably in your FlapIdent function.

It that's the case, it's a problem in your
implementation of the ICQ protocol and therefore
not a Palm OS issue.

You should use a debugger and view exactly the packet
you are sending, and compare that with a sniffed
packet from your other client that you said works.

Sorry I can't say any more.
0
 
LVL 16

Author Comment

by:Peter Kwan
ID: 8156656
Thanks anyway.

One more question, can I configure in the Palm emulator settings so that I can see what is being sent to the server using NetLibSend? If yes, how to do it?

Thanks.
0
 
LVL 3

Expert Comment

by:olan75
ID: 8175699
Not that I know of.
You can use a winsock sniffer.
Or, you can use PalmReporter and the HostTraceOutputB function to trace what you're sending/receiving.
I have had success with both methods in the past.

0
 
LVL 3

Expert Comment

by:olan75
ID: 9798712
Although the OP provided no feedback, the methods suggested should have helped him solve his problem (they did require him to do more work).
Thanks
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question