MadDavid
asked on
Need to connect to internet on Win 98SE (get 10049 on connect)
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.
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.
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.
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.
ASKER
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::Button2Clic k(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::ClientSocke t1Lookup(T Object *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::ClientSocke t1Connecti ng(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::ClientSocke t1Connect( 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(P ostMessage .c_str(),P ostMessage .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(&(Cur rentBuffer [1]), 1);
if (Test)
{
TotalReturn = TotalReturn + CurrentBuffer;
}
}while ((Test > 0));
TotalReturn = TotalReturn + " ";
TotalReturn[TotalReturn.Le ngth()] = 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::ClientSocke t1Disconne ct(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::ClientSocke t1Error(TO bject *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(Er rorMessage .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. ;)
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::Button2Clic
{
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::ClientSocke
TCustomWinSocket *Socket)
{
logout("KISLog.txt", "Here7");
dlgRegistering->lblMessage
logout("KISLog.txt", "Here8");
dlgRegistering->Repaint();
logout("KISLog.txt", "Here9");
}
//------------------------
void __fastcall TdlgInputUCID::ClientSocke
TCustomWinSocket *Socket)
{
logout("KISLog.txt", "Here10");
dlgRegistering->lblMessage
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-
Out[Out.Length()] = 0;
logout("KISLog.txt", &(Out[1]));
}
//------------------------
void __fastcall TdlgInputUCID::ClientSocke
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(P
{
AnsiString Out = "Address = " + ClientSocket1->Address + " ";
Out[Out.Length()] = 0;
logout("KISLog.txt", &(Out[1]));
Out = "Port = " + (AnsiString)ClientSocket1-
Out[Out.Length()] = 0;
logout("KISLog.txt", &(Out[1]));
logout("KISLog.txt", "Here16");
dlgRegistering->lblMessage
dlgRegistering->Repaint();
do
{
Test = MySocketStream->Read(&(Cur
if (Test)
{
TotalReturn = TotalReturn + CurrentBuffer;
}
}while ((Test > 0));
TotalReturn = TotalReturn + " ";
TotalReturn[TotalReturn.Le
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::ClientSocke
TCustomWinSocket *Socket)
{
logout("KISLog.txt", "Here18");
dlgRegistering->lblMessage
logout("KISLog.txt", "Here19");
dlgRegistering->Repaint();
logout("KISLog.txt", "Here20");
}
//------------------------
void __fastcall TdlgInputUCID::ClientSocke
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(Er
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. ;)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, cwwkie.
I just downloaded ICS, and I'll get back to you as soon as I know whether it works.
I just downloaded ICS, and I'll get back to you as soon as I know whether it works.
ASKER
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
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
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)