Solved

Need to connect to internet on Win 98SE (get 10049 on connect)

Posted on 2006-07-18
6
486 Views
Last Modified: 2013-11-17
I'm having trouble getting a BCB 6.0 TClientSocket to connect to the internet on a Windows 98SE machine.

I've written the code (on a Windows XP computer) to transmit user registration information to my website.  It uses a TClientSocket to connect to www.ducksnm.com, and then uses a TWinSocketStream to transmit the information and receive a reply.  On the Windows XP computers, this works fine.  On the Windows 98SE computer, I get a messagebox saying "Windows socket error (10049) on API 'connect.' "  Other people have had similar problems, but the answers on EE and the Usenet have not been helpful.

Here's what I've found:

On the Windows 98SE computer, the error is occurring during or after the TClientSocket's OnConnecting event (when it *supposedly* has looked up the address of the server and before it actually establishes the connection) and before the OnConnect event  (It never enters the developer-defined OnConnect function.)  It does not trigger the OnError event.  The error occurs whether I try to specify the site by setting the Host or the Address property of the TClientSocket.

On the Windows XP computer, I've discovered that:
When I specify the server by setting the Host property of the TClientSocket, the Address property remains blank throughout the connection and transmission.  This is interesting because the BCB help says that the OnConnecting event "is the first opportunity to obtain the actual port and IP address of the server endpoint of the connection that is about to form," implying that Address *should* be set sometime during lookup, so that you can read it.  Also, when I connect by setting Address and clearing Host, the TClientSocket connects to a DNS server anyway.  (Correct me if I'm wrong, but I thought that DNS servers existed to find the IP address associated with a domain name.  If the TClientSocket has an IP address and *no domain name*, why is it connecting to a DNS?)


My main $100 question is, is there any reliable solution that will let me connect to the internet and stream information to and from a website on both Windows 98SE and Windows XP?  (And presumably everything in between.)  The solution could include (preferably free) third-party packages or implementing multiple methods for different operating systems.  Or requiring that certain (preferably official Microsoft) free software be installed on the user's computer.
0
Comment
Question by:MadDavid
[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
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:cwwkie
ID: 17133953
Can you reproduce this problem using a small test program, doing for example a query on google?
If you can post such a program, it would make it for us a bit easier, and guarantees for example it is not related to your website;

If the example is a bit longer, you can post it on ee-stuff.com (http://www.ee-stuff.com/Expert/Upload/viewFilesQuestion.php?qid=21923611)
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 17139769
This behavor is strange...
I personaly using TServer/TClient sockets for more than 4 years now and didn't had something like that...
Can you post how you are assigning the host and port to the TClientSocket??
Is that assign at the object inspector or at runtime??

George Tokas.
0
 
LVL 1

Author Comment

by:MadDavid
ID: 17169359
In response to gtokas' question, I am setting the Service and Host/Address properties of the TClientSocket at design time through the object inspector.

In response to cwwkie's comment, I pared the code down to its essentials, changed the POST message to a GET message and changed the host to www.nmia.com, and I got the same results.  Here's the code:

    (TClientSocket ClientSocket1 has the following properties set through the Object Inspector:
    Active = false
    Address = ""
    ClientType = ctBlocking
    Host = www.nmia.com
    Port = 0
    Service = http
    Tag = 0)

    void __fastcall TdlgInputUCID::Button2Click(TObject *Sender)
    {
            logout("KISLog.txt", "Here1");
            //This prints "Here1\n" to "KISLog.txt".  I'm using it to track what lines I actually reach when the program
            //executes
    ClientSocket1->Close();
            logout("KISLog.txt", "Here2");
    dlgRegistering->Show();
            logout("KISLog.txt", "Here3");
    ClientSocket1->Open();
            logout("KISLog.txt", "Here4");
    dlgRegistering->Hide();
            logout("KISLog.txt", "Here5");
    return;
    }
    //---------------------------------------------------------------------------

    void __fastcall TdlgInputUCID::ClientSocket1Lookup(TObject *Sender,
          TCustomWinSocket *Socket)
    {
            logout("KISLog.txt", "Here7");
    dlgRegistering->lblMessage->Caption = "Looking up registration site...";
            logout("KISLog.txt", "Here8");
    dlgRegistering->Repaint();
            logout("KISLog.txt", "Here9");
    }
    //---------------------------------------------------------------------------

    void __fastcall TdlgInputUCID::ClientSocket1Connecting(TObject *Sender,
          TCustomWinSocket *Socket)
    {
            logout("KISLog.txt", "Here10");
    dlgRegistering->lblMessage->Caption = "Connecting to registration site...";
            logout("KISLog.txt", "Here11");
    dlgRegistering->Repaint();
            logout("KISLog.txt", "Here12");
        AnsiString Out = "Address = " + ClientSocket1->Address + " ";
        Out[Out.Length()] = 0;
        logout("KISLog.txt", &(Out[1]));
        Out = "Port = " + (AnsiString)ClientSocket1->Port + " ";
        Out[Out.Length()] = 0;
        logout("KISLog.txt", &(Out[1]));
    }
    //---------------------------------------------------------------------------

    void __fastcall TdlgInputUCID::ClientSocket1Connect(TObject *Sender,
          TCustomWinSocket *Socket)
    {
            logout("KISLog.txt", "Here13");
    TWinSocketStream* MySocketStream = new TWinSocketStream(Socket, 10000);
            logout("KISLog.txt", "Here14");

    AnsiString CurrentBuffer, TotalReturn;
    AnsiString PostMessage = "GET /index.html HTTP/1.1\nHost: www.nmia.com\n\n";
    CurrentBuffer = " ";
    TotalReturn = "";
    int Test;
    lblRegStr->Caption = "";
            logout("KISLog.txt", "Here15");
    if(MySocketStream->Write(PostMessage.c_str(),PostMessage.Length()))
      {
          AnsiString Out = "Address = " + ClientSocket1->Address + " ";
          Out[Out.Length()] = 0;
          logout("KISLog.txt", &(Out[1]));
          Out = "Port = " + (AnsiString)ClientSocket1->Port + " ";
          Out[Out.Length()] = 0;
          logout("KISLog.txt", &(Out[1]));
              logout("KISLog.txt", "Here16");
      dlgRegistering->lblMessage->Caption = "Sending Registration Information...";
      dlgRegistering->Repaint();
      do
        {
        Test = MySocketStream->Read(&(CurrentBuffer[1]), 1);
        if (Test)
          {
          TotalReturn = TotalReturn + CurrentBuffer;
          }
        }while ((Test > 0));
      TotalReturn = TotalReturn + " ";
      TotalReturn[TotalReturn.Length()] = 0;
      logout("KISLog.txt", &(TotalReturn[1]));
      //If the connection is successful, this prints out the index.html in KISLog.txt.
      }
    else
      {
              logout("KISLog.txt", "Here17");
      lblRegStr->Caption = "timeout";
      }
    delete MySocketStream;
    }
    //---------------------------------------------------------------------------
 
    void __fastcall TdlgInputUCID::ClientSocket1Disconnect(TObject *Sender,
          TCustomWinSocket *Socket)
    {
            logout("KISLog.txt", "Here18");
    dlgRegistering->lblMessage->Caption = "Disconnected";
            logout("KISLog.txt", "Here19");
    dlgRegistering->Repaint();
            logout("KISLog.txt", "Here20");
    }
    //---------------------------------------------------------------------------

    void __fastcall TdlgInputUCID::ClientSocket1Error(TObject *Sender,
          TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
    {
            logout("KISLog.txt", "Here21");
    AnsiString ErrorMessage = "Error " + (AnsiString)ErrorEvent + "\n";
    switch(ErrorEvent)
      {
      case eeGeneral:
      ErrorMessage = ErrorMessage + "The socket received an error\nmessage that does not fit into\nany of the
        following categories.";
      break;

      case eeSend:
      ErrorMessage = ErrorMessage + "An error occurred when trying\nto write to the socket connection.";
      break;

      case eeReceive:
      ErrorMessage = ErrorMessage + "An error occurred when trying\nto read from the socket connection.";
      break;

      case eeConnect:
      ErrorMessage = ErrorMessage + "A connection request that was\nalready accepted could not be\ncompleted.";
      break;

      case eeDisconnect:
      ErrorMessage = ErrorMessage + "An error occurred when trying\nto close a connection.";
      break;

      case eeAccept:
      ErrorMessage = ErrorMessage + "A problem occurred when trying\nto accept a client connection request.";
      break;
      }
            logout("KISLog.txt", "Here22");
    Application->MessageBox(ErrorMessage.c_str(), "");
            logout("KISLog.txt", "Here23");
    ErrorCode = 0;
    }
    //---------------------------------------------------------------------------

When I run this on Windows XP, everything works.

When I run this on Windows 98SE, I get the "Error 10049 on connect", and the KISLog.txt reads
    Here1
    Here2
    Here3
    Here7
    Here8
    Here9
    Here10
    Here11
    Here12
    Address =
    Port = 0
    Here18
    Here19
    Here20
 
Indicating that it looked up the site, tried to connect, disconnected without entering the OnConnect event, got the "(10049) on API 'connect' " error without entering the OnError event, and aborted the Button2Click program without finishing up.  (I had to close dlgRegistering manually)

> This behavior is strange...
That's what I thought, and why I'm open to just about any workaround. ;)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Accepted Solution

by:
cwwkie earned 250 total points
ID: 17187971
I think it is a kind of timing issue. When I run it on a win9X box with a firewall, I get the dns lookup popup AFTER the error message.

Maybe you can try ICS (http://www.overbyte.be/frame_index.html?redirTo=/products/ics.html) I could use it's WSocket without any problem. I have no time to create a larger test program, but at least the connect is working on win9X.


I have two unrelated comments;

Instead of writing to a log file, OutputDebugString can be usefull in combination with Debugview (http://www.sysinternals.com/Utilities/DebugView.html)

To try it, you can use this define without any further changes in the code:
#define logout(f,txt) OutputDebugString(txt)
If you run the program from within the ide, the strings will be sent to the internal event viewer.

>        AnsiString Out = "Address = " + ClientSocket1->Address + " ";
>        Out[Out.Length()] = 0;
>        logout("KISLog.txt", &(Out[1]));

It is easier to do this:
        AnsiString Out = "Address = " + ClientSocket1->Address + " ";
        logout("KISLog.txt", Out.c_str());
0
 
LVL 1

Author Comment

by:MadDavid
ID: 17188740
Thanks, cwwkie.

I just downloaded ICS, and I'll get back to you as soon as I know whether it works.
0
 
LVL 1

Author Comment

by:MadDavid
ID: 17197291
Thanks again, cwwkie.

ICS's WSocket just checked out on my Win 98SE computer, and I couldn't ask for more.

Just a few interesting (& undocumented) installation hang-ups, which I will post later.  (Right now, there's a severe thunderstorm warning).

But, problem is solved
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

739 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