Mega Search
23.2 Million


Sign Up

Make a donation  
With TCustomWinSock How to retry Open()  
News Group: embarcadero.public.cppbuilder.internet.socket

I am using the depreciated component TCustomWinSocket in CB XE4 with the VCL Windows 32 platform.  When I call Socket->Open() I sometimes get the Error Event, eeConnect (A connection request that was already accepted could not be completed). At the current time I have to restart the application to open the socket. Can someone show how I would reset the socket and try to open the socket again without restarting the app. Below is my code for opening the socket and the error event.  Thanks.   


  
  if(MySocket_M->Socket->Connected == false)
  {
	MySocket_M->Port = MyGetFeedPort("DataPort");
	MySocket_M->Open();
  }



void __fastcall TMainForm::MySocket_MError(TObject *Sender, TCustomWinSocket *Socket,
		  TErrorEvent ErrorEvent, int &ErrorCode)
{

  UnicodeString eemsg, msg;

  if(ErrorEvent==eeGeneral){
	eemsg ="Socket Error. Unknown generic Socket error.(Msg 29359)";
  }else if(ErrorEvent==eeSend){
	eemsg ="Socket Error. An error occurred when trying to write to the socket connection.(Msg 29360)";
  }else if(ErrorEvent==eeReceive){
	eemsg ="Socket Error. An error occurred when trying to read from the socket connection.(Msg 29361)";
  }else if(ErrorEvent==eeConnect){
	eemsg ="Socket Error. A connection request that was already accepted could not be completed. (Msg 10061)";
  }else if(ErrorEvent==eeDisconnect){
	eemsg ="Socket Error. An error occurred when trying to close a connection.(Msg 29363)";
  }else if(ErrorEvent==eeAccept){
	eemsg ="Socket Error. A problem occurred when trying to accept a client connection request.(Msg 29364)";
  }else{
	eemsg ="Socket Error. Server is not available to Socket Port.(Msg 29365)";
  }

  msg = eemsg+" Error Number("+IntToStr(ErrorCode)+")";
  ShowMessage( msg );
  ErrorCode=0;
 
}
//---------------------------------------------------------------------------

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 23-Jan-2015, at 10:35 AM EST
From: Patrick Mikula