FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Wsa error 10048
Posts: 113
Joined: Wed Feb 08, 2006 10:32 PM
Wsa error 10048
Posted: Thu Mar 05, 2026 01:48 PM

Hi all, after a couple of mail correctly sent, when sending the next I receive the following error:

Could not establish connection to smtp3.aruba.it - WSA Error Code: 10048

I know it has to do with port release but I don't know how to fix it.

current version: FW2512 64bit

previous version FW2002 32bit (no errors with the same procedure)

thank you

Roberto Chiaiese
R&C Informatica S.n.c.
https://www.recinformatica.it
info@recinformatica.it

Harbour 3.2 - FW2512

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Wsa error 10048
Posted: Thu Mar 05, 2026 02:02 PM

The error code WSA 10048 (known as WSAEADDRINUSE) indicates that the network address (IP and Port) is already in use.

This occurs when a program attempts to open a communication port that is already occupied by another application or by a previous instance of the same program that was not properly terminated.

Post the code for feedback.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Wsa error 10048
Posted: Thu Mar 05, 2026 03:25 PM

What's the difference between smtps.aruba.it and smtp3.aruba.it? I never heard of the latter.

Posts: 113
Joined: Wed Feb 08, 2006 10:32 PM
Re: Wsa error 10048
Posted: Thu Mar 05, 2026 04:11 PM

Enrico,

I believe that Aruba performs an internal redirection of emails between its servers. It seems to be used from smtp legacy servers instead of standard smtps new servers

Roberto

Roberto Chiaiese
R&C Informatica S.n.c.
https://www.recinformatica.it
info@recinformatica.it

Harbour 3.2 - FW2512

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Wsa error 10048
Posted: Thu Mar 05, 2026 05:29 PM

I recently had to switch a customer from smtp.hisdomain.it to smtps.aruba.it as the former didn't work anymore on a specific PC (on the other PCs it kept working just fine).

Posts: 113
Joined: Wed Feb 08, 2006 10:32 PM
Re: Wsa error 10048
Posted: Thu Mar 05, 2026 05:52 PM

here is the function I use to send emails:

******************************************************************************
// add: <cMitt> come parametro opzionale - 30/03/2019
function Spedisci(oWnd,aAddr,cOggetto,cText,cHtm,aAllega,lSilent,aCC,aCCn,nPort,cMitt,cPwd)
local lRet, nTime := 0
local oMail	
local cServer, cUser, lReceipt

if SETUP->(fieldpos("SMTPSERV")) > 0					// ctrl se esiste campo su Setup
	default cMitt to trim(SETUP->MailMitte)				// mittente
	cServer := trim(SETUP->SmtpServ)					//
	cUser   := trim(SETUP->SmtpUser)					//
	default cPwd := trim(SETUP->SmtpPass)				// mod: default - 14/03/2025
endif
if SETUP->(fieldpos("SMTPPORT")) > 0					// ctrl se esiste campo su Setup
	default nPort := val(alltrim(SETUP->SmtpPort))		// porta Smtp
endif

// valori di default
cMitt	:= if(!empty(cMitt),cMitt,"support@mydomain.it")		// mittente
cServer	:= if(!empty(cServer),cServer,"smtp.mydomain.it")		// mailserver
cUser	:= if(!empty(cUser),cUser,"support@mydomain.it")		// username x autenticazione
cPwd	:= if(!empty(cPwd),cPwd,"mypassword")					// password
nPort	:= if(!empty(nPort), nPort, 25	)						// add: nPort - 30/03/2018

default aAddr := {}										// add: 09/10/2021
default aCC := {}										//
default aCCn := {}										//
aEval(aAddr,{|c,n| aAddr[n] := alltrim(c) })			// add: 09/10/2021
aEval(aCC,	{|c,n| aCC[n] := alltrim(c) })				//
aEval(aCCn,	{|c,n| aCCn[n] := alltrim(c) })				//

if oApp:lDemo .and. !lSilent
	msginfo("Impossibile inviare mail in modalità demo.")
	return (.f.)
endif

oMail := TSmtp():New(cServer, nPort, .t., cUser, cPwd)		// .t. = autenticazione
//tracelog(cMitt,cServer,cUser,cPwd,oMail:cIpServer)

oMail:bConnected  := {|| piede("Connesso, invio in corso..."+aAddr[1]) }
oMail:bConnecting := {|| piede("In connessione..."), cursorwait() }
oMail:bDone		:= {|oSmtp| /*WSACleanup(), */ piede("messaggio inviato."), lRet := .t. }	// add: WSACleanup() 27/02/2026
#ifdef CGI
	oMail:bFailure	:= {|oSmtp,cErr,cLastReply| tracelogNew( {cErr," Last reply: "+cLastReply}, "SendMail.log" ), lRet := .f. }
#else
	#ifdef FW2512
		// mod: 27/02/2026
		oMail:bFailure	:= {|oSmtp,nWSAErr,cLastReply| alert("WSA Error Code: "+AllTrim(Str(nWSAErr))+" Last reply: "+cLastReply,,,,,8),;
														tracelogNew({nWSAErr," Last reply: "+cLastReply}, "SendMail.log"),;
														lRet := .f. }
	#else
		oMail:bFailure	:= {|oSmtp,cErr,cLastReply| alert(cErr+" Last reply: "+cLastReply,,,,,8),;
													tracelogNew({cErr," Last reply: "+cLastReply}, "SendMail.log"),;
													lRet := .f. }
	#endif
#endif

oMail:nDelay   := 5           // era 1.5 - 19/03/2009 - 10/06/2009 - 5=05/09/2014
oMail:SendMail(cMitt,aAddr,cText,cOggetto,aAllega,aCC,aCCn,lReceipt,cHtm)

while lRet == nil .and. nTime++ < 60					// 1 min max per ogni mail
    cursorwait()
    sysrefresh()
    sysWait(1)
end
piede()
cursorArrow()
default lRet to ( oMail:end(), .f. )					// add: oMail:end() - 05/04/2018

tracelogNew( {if( lRet,"","Non ")+"Spedita => "+cServer, cMitt, aAddr, aCC, aCCn,;
				"last reply: "+cvalToChar(atail(oMail:acReply)),;
				"last error: "+oMail:cError, "Status: "+alltrim(str(oMail:nStatus)),;
				nTime, cOggetto, cText, cHtm, aAllega }, "SendMail.log" )
#ifdef FW2512
	syswait(0.2)										// microsleep - 05/03/2026
#endif

return (lRet)

Roberto Chiaiese
R&C Informatica S.n.c.
https://www.recinformatica.it
info@recinformatica.it

Harbour 3.2 - FW2512

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Wsa error 10048
Posted: Thu Mar 05, 2026 06:03 PM

https://www.aruba.it/en/home.aspx

AI-generated overview:

The Aruba.it/Aruba PEC email service primarily uses Secure SMTP (SMTP Secure) to ensure encryption of outgoing messages.

Here are the recommended settings for the outgoing server (SMTP):

SMTP Server (Outgoing): smtps.pec.aruba.it (for PEC) or smtp.aruba.it (for regular domains).

Port: 465

Security/Encryption: SSL/TLS

Authentication: Required (using your full username and password).

While port 25 (unencrypted) may work in some cases, using SMTP on port 465 is the recommended and most secure standard.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Wsa error 10048
Posted: Thu Mar 05, 2026 06:08 PM

No, not with smtp.aruba.it, it doesn't work with SSL (just tried), it must be smtps.aruba.it.

Posts: 113
Joined: Wed Feb 08, 2006 10:32 PM
Re: Wsa error 10048
Posted: Thu Mar 05, 2026 07:19 PM

I think the problem is not which server I use or if I use SSL or not.

Actually I have a program compiled with FW2002 32 bit that is runnig h24 for some years with smtp sever (no ssl), automatically sending a lot of email everyday for various purposes

The same program compiled with FW2512 64bit using the same parameters fails after just 2 or 3 emails with WSA error 10048

So it's clear to me that it's not a mail server or SSL issue but perhaps a speed issue involving opening/closing ports I think I will try increasing the 'microsleep' at the end of the function

Roberto Chiaiese
R&C Informatica S.n.c.
https://www.recinformatica.it
info@recinformatica.it

Harbour 3.2 - FW2512

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Wsa error 10048
Posted: Thu Mar 05, 2026 08:16 PM

Dear friends,

This is deepwiki analysis:

Here's the root cause analysis and solution for the WSA Error 10048 issue.

Root Cause

The problem is in TSocket:New(). When TSmtp:New() creates a socket, it passes the SMTP port (e.g., 25) to TSocket:New(), which then calls BindToPort() to bind the local socket to that port:

Code (prg): Select all Collapse
if nPort != nil
   ::nPort = nPort
   BindToPort( ::nSocket, nPort )  // Bind is not needed for connect sockets
endif
``` [0-cite-0](#0-cite-0) 

The comment in the code even says: **"Bind is not needed for connect sockets"**. For an SMTP client, you only need to *connect to* the remote port — you should not *bind* the local socket to that same port. After the first email is sent and the socket is closed, the OS keeps port 25 in a `TIME_WAIT` state (typically 30-240 seconds on Windows). The next `TSmtp:New()` creates a new socket and tries to bind to local port 25 again, which fails with `WSAEADDRINUSE` (10048).

The `BindToPort` C function in `winsock.c` calls the Windows `bind()` API: [0-cite-1](#0-cite-1) 

The error surfaces in `TSmtp:OnConnect()`, where the `FD_CONNECT` event fires with error code 10048: [0-cite-2](#0-cite-2) 

## Why it worked in FW2002 32-bit

The 32-bit `WSAStartup` uses WinSock version `0x101` (1.1), while the newer/Unicode builds use `0x202` (2.2). Different WinSock versions may handle `TIME_WAIT` and port reuse differently. Also, 32-bit execution is typically slower, potentially giving more time for port cleanup between sends. [0-cite-3](#0-cite-3) 

## Why `syswait(0.2)` won't fix it

The Windows TCP `TIME_WAIT` period is typically **30 to 240 seconds**, not 200 milliseconds. A `syswait(0.2)` is far too short.

## Recommended Fix

The proper fix is in `TSocket:New()` — it should **not call `BindToPort()`** when the socket is used as a client (connect) socket. Since this is a FiveWin framework issue, I would recommend reporting it to Antonio Linares.

As a **workaround** in your `Spedisci` function, you can set `SO_REUSEADDR` on the socket right after creating the `TSmtp` object, before calling `SendMail`. This tells the OS to allow binding to a port that's in `TIME_WAIT`:

```prg
#define SOL_SOCKET    -1      // or 0xFFFF
#define SO_REUSEADDR   4

oMail := TSmtp():New(cServer, nPort, .t., cUser, cPwd)

// Allow reuse of port in TIME_WAIT state
SetSockOpt( oMail:oSocket:nSocket, SOL_SOCKET, SO_REUSEADDR, 1 )

However, note that SO_REUSEADDR must be set before bind() for it to take effect, and the bind() already happened inside TSocket:New(). So this workaround may not fully resolve the issue. 0-cite-4

The most reliable workaround is to modify TSmtp:New() to not pass the port to TSocket:New(), and instead set the port on the socket object afterward:

Code (prg): Select all Collapse
// In TSmtp:New(), change:
//   ::oSocket := TSocket():New( nPort )
// To:
   ::oSocket := TSocket():New()        // Don't bind to any local port
   ::oSocket:nPort := nPort            // Store port for ConnectTo() to use
``` [0-cite-5](#0-cite-5) 

This way, `TSocket:New()` skips the `BindToPort()` call (since `nPort` is nil), and the port is still available for the `ConnectTo()` call via `::oSocket:nPort`: [0-cite-6](#0-cite-6) 

Alternatively, the `TSocket:New()` method could be modified to set `SO_REUSEADDR` before calling `BindToPort`:

```prg
if nPort != nil
   ::nPort = nPort
   SetSockOpt( ::nSocket, SOL_SOCKET, SO_REUSEADDR, 1 )  // Add this line
   BindToPort( ::nSocket, nPort )
endif

Both of these require modifying FiveWin source files (tsmtp.prg or tsocket.prg). The first approach (not passing port to TSocket:New()) is the cleaner solution since client sockets shouldn't bind to a local port at all.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 113
Joined: Wed Feb 08, 2006 10:32 PM
Re: Wsa error 10048
Posted: Fri Mar 06, 2026 01:56 PM

Antonio,
I just modified my function:

#ifdef FW2512
	oMail := TSmtp():New(cServer,, .t., cUser, cPwd)			// .t. = autenticazione
	oMail:oSocket:nPort := nPort							// set port after obj init - 06/03/2026
#else
	oMail := TSmtp():New(cServer, nPort, .t., cUser, cPwd)		// .t. = autenticazione
#endif

sent 20 emails in a loop and now it works!
thank you

Roberto Chiaiese
R&C Informatica S.n.c.
https://www.recinformatica.it
info@recinformatica.it

Harbour 3.2 - FW2512

Continue the discussion