Board index » delphi » 10048 WSAEADDRINUSE "Address already in use" Error
|
Gregory A. Dunn
Delphi Developer |
10048 WSAEADDRINUSE "Address already in use" Error2004-09-29 10:03:55 PM delphi173 Hello, I am using the TTcpClient object in a multi-threaded application to simultaneously communicate to several field devices. I am using one TTcpClient object in each of my communications threads. The application seems to work pretty well for the most part but I get the following Winsock Error on a regular basis: Any suggestions on resolving the problem would be much appreciated. Details on the issue are show below: ################################### WSAEADDRINUSE (10048) Address already in use. Only one usage of each socket address (protocol/IP address/port) is normally permitted. This error occurs if an application attempts to bind a socket to an IP address/port that has already been used for an existing socket, or a socket that wasn't closed properly, or one that is still in the process of closing. For server applications that need to bind multiple sockets to the same port number, consider using setsockopt (SO_REUSEADDR). Client applications usually need not call bind at all - connect will choose an unused port automatically. ##################################### I use the following sequence to open, communicate and then close the connections:: This code only gives the general sequence, the actual code is complex with error handling etc. Extra code has been removed for this example. TCPClient.Open; repeat BytesRead := TCPClient.ReceiveBuf(RxBuf,RxBufSize); // dosomething with received data // send out data if necessary if [Needed] then TCPClient.Sendln(MsgSendStr,''); until [Finished Processing] TCPClient.Close; After communications is complete with one unit, there is a delay of one secnod and then the process is repeated with another unit. In my testing, I have 5 units in the test which are communicated with repeatadly in this fashion. The error seems to occur every 1-15 minutes or so. How can I work around this problem? Thanks, Greg Dunn XXXX@XXXXX.COM 304-757-6565 ext 117 |
