avatar
socket re-connection problem# Programming - 葵花宝典
mw
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
avatar
m*e
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

avatar
mw
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.

avatar
m*n
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

avatar
c*e
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

avatar
l*l
6
man socket
man writen
man readline

【在 m*******n 的大作中提到】
: 我也正在写一个TCP程序。
: 你是怎么知道一个函数需要哪个lib的。例如,socket 使用 socket lib.但是,writen
: ,readline 使用的是什么lib
: 本人仍然没有链接成功。:-(
:
: just

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。