mw 发帖数: 525 | 1 Now i have a TCP/IP, server program. It uses its ip address and port number to
bind a socket ,then listen and connect.
The problem is , after the client side is shutdown, it needs to re-connect.
But after I "closesocket", how can i re-setup this connection ?
My process is "open socket again" ->setsockopt->bind, but the "bind" just
fails and complains that the port is in use. Wierd! I have already shutdown
the socket use "closesocket", there should not be such problem at all...
can anyone help?
t | m*****e 发帖数: 4193 | 2
You don't close the socket bind() returns. You close the one accept()
returns. And if you do this way, of course you cannot bind() it again.
【在 mw 的大作中提到】 : Now i have a TCP/IP, server program. It uses its ip address and port number to : bind a socket ,then listen and connect. : The problem is , after the client side is shutdown, it needs to re-connect. : But after I "closesocket", how can i re-setup this connection ? : My process is "open socket again" ->setsockopt->bind, but the "bind" just : fails and complains that the port is in use. Wierd! I have already shutdown : the socket use "closesocket", there should not be such problem at all... : can anyone help? : t
| mw 发帖数: 525 | 3 yi ju hua dian xing meng zhong ren
i really appreciate your immediate help!thanks alot!
number to
re-connect.
shutdown
【在 m*****e 的大作中提到】 : : You don't close the socket bind() returns. You close the one accept() : returns. And if you do this way, of course you cannot bind() it again.
| m*******n 发帖数: 103 | 4 我也正在写一个TCP程序。
你是怎么知道一个函数需要哪个lib的。例如,socket 使用 socket lib.但是,writen
,readline 使用的是什么lib
本人仍然没有链接成功。:-(
just
【在 mw 的大作中提到】 : yi ju hua dian xing meng zhong ren : i really appreciate your immediate help!thanks alot! : : number to : re-connect. : shutdown
| c********e 发帖数: 383 | 5 dont quite understand what you said ....but if you are binding the client
program who is doing the connect call, 1. you dont have to you can use the
em..port that the kernal gives you. INET_ANY 2, there is a socket option to
make the socket reusable check man page for setsockopt. this is usually for
sockets in the waiting state.
【在 mw 的大作中提到】 : Now i have a TCP/IP, server program. It uses its ip address and port number to : bind a socket ,then listen and connect. : The problem is , after the client side is shutdown, it needs to re-connect. : But after I "closesocket", how can i re-setup this connection ? : My process is "open socket again" ->setsockopt->bind, but the "bind" just : fails and complains that the port is in use. Wierd! I have already shutdown : the socket use "closesocket", there should not be such problem at all... : can anyone help? : t
| l*l 发帖数: 26 | 6 man socket
man writen
man readline
【在 m*******n 的大作中提到】 : 我也正在写一个TCP程序。 : 你是怎么知道一个函数需要哪个lib的。例如,socket 使用 socket lib.但是,writen : ,readline 使用的是什么lib : 本人仍然没有链接成功。:-( : : just
|
|