| |

VerySource

 Forgot password?
 Register
Search
View: 1382|Reply: 7

Error when calling bind (): Usually each socket address (...) is allowed to be used only once, how to solve it?

[Copy link]

2

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-21 17:00:01
| Show all posts |Read mode
The general flow of the program is this:

1) Create a socket object with socket ()
2) Bind the socket object to the specified address and port with bind ()
3) listen () starts listening
4) closesocket () when closing the program

There is no problem during normal operation, but if the program exits due to an illegal operation before closing it, when you restart the program, you will get an error when running to bind (): "Usually each socket address (protocol / network address / port) Only allowed once ", error number is 10048
And at this time, you can only log out of the operating system and restart it.
I want to know when I judge this error number, is there a method in the socket library function that can release the originally bound port? Experts specify one or two, thank you!
Reply

Use magic Report

0

Threads

10

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-30 13:15:01
| Show all posts
Try WSACleanup
Reply

Use magic Report

0

Threads

10

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-1 06:00:01
| Show all posts
Or use setsockopt to set SO_REUSEADDR
Reply

Use magic Report

0

Threads

24

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-7-1 10:15:01
| Show all posts
Wait about 30 seconds. Wait for TCP to become CLOSED. I have seen the state transition diagram of TCP.
Reply

Use magic Report

0

Threads

70

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-7-4 09:45:01
| Show all posts
Address multiplexing SO_REUSEADDR
Reply

Use magic Report

0

Threads

59

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-7-6 14:15:02
| Show all posts
Local method: disable and enable the network
Reply

Use magic Report

2

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-7-26 06:30:01
| Show all posts
I tried WSACleanup
Address reuse SO_REUSEADDR, I originally wanted to try, but because my program was developed by PB, I don’t know how to call this library function (due to the parameter type problem, the call is always unsuccessful), I guess this method is OK
Native method: disable and then enable the network--this is not suitable
Waiting for 30 seconds doesn’t seem to work. I have this problem, even if I wait for a long time, I have to restart it.
================================================= ===============================
I finally call closesock() in the program system error event
Reply

Use magic Report

2

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-7-26 07:45:01
| Show all posts
Thank you for your attention.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list