套接字连接与绑定?有什么不同 [英] Socket connect vs. bind? What is the difference

查看:69
本文介绍了套接字连接与绑定?有什么不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作多播服务器客户端设置,并想知道Socket.Connect和Socket.Bind之间的区别是什么。


它可能是一个愚蠢的问题,但我只是好奇。因为我尝试了一个

测试,我不能将两个套接字绑定到同一个端口/ ip但是我可以

连接一个套接字,并绑定到另一个套接字相同的IP /端口。


谢谢

I am makeing a Multicast server client setup and was wondering what the
difference is between Socket.Connect, and Socket.Bind.

It may be a stupid question, but I was just curious. Because I tried a
test, and I can''t bind two sockets to the same port/ip but I can
connect with one socket, and bind with another to the same ip/port.

Thanks

推荐答案

绑定一个Socket与一个本地IPEndPoint。 Connect将Socket

连接到远程IPEndPoint。


-

HTH,


Kevin Spencer

微软MVP

专业发展Numbskull


Nyuck nyuck nyuck

" ; DaTurk" <毫米****** @ hotmail.com>在消息中写道

新闻:11 ********************** @ h76g2000cwa.googlegr oups.com ...
Bind associates a Socket with a local IPEndPoint. Connect connects a Socket
to a remote IPEndPoint.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Development Numbskull

Nyuck nyuck nyuck
"DaTurk" <mm******@hotmail.com> wrote in message
news:11**********************@h76g2000cwa.googlegr oups.com...
我正在制作一个多播服务器客户端设置,并想知道Socket.Connect和Socket.Bind之间的区别是什么。

这可能是一个愚蠢的问题,但我只是好奇。因为我尝试了一个
测试,我不能将两个套接字绑定到同一个端口/ ip,但我可以用一个套接字连接,并与另一个套接字绑定到同一个ip / port。 />
谢谢
I am makeing a Multicast server client setup and was wondering what the
difference is between Socket.Connect, and Socket.Bind.

It may be a stupid question, but I was just curious. Because I tried a
test, and I can''t bind two sockets to the same port/ip but I can
connect with one socket, and bind with another to the same ip/port.

Thanks



感谢您的回复,但您对联营公司究竟是什么意思,并且

connect 。我想我要问的是有什么不同,当你想要使用一个而不是另一个时,有什么情况。


At这一点我正在使用套接字创建一个多播套接字服务器

setup,在我看到的例子中,发送的套接字通常连接,

和监听的套接字绑定。

Thanks for the reponse, but what exactly do you mean by associate, and
connect. I guess what I''m asking is what is the difference, and when
would you want to use one over the other, what situations.

At this point I''m using sockets to create a multicast socket server
setup, and in examples I saw, the socket that sends typically connects,
and the socket that listens binds.


这是正确的,因为监听器是服务器。您可以将多个

客户端连接到服务器套接字。它比

稍微复杂一点,但基本上,你想将你的服务器绑定到服务器套接字并且

将它设置为Listen。然后您的客户端将连接到服务器套接字以使
与服务器应用程序进行交互。服务器在尝试连接时要为每个要接受的
客户端调用Accept。每个客户

将拥有自己的IPEndPoint,它由IP地址和端口组成。


-

HTH,


Kevin Spencer

Microsoft MVP

专业鸡肉沙拉炼金术士


终身由

组成。很多短暂的时刻。


DaTurk <毫米****** @ hotmail.com>在消息中写道

news:11 ********************** @ j55g2000cwa.googlegr oups.com ...
That''s correct, because the listener is the server. You can have multiple
clients connect to the server socket. It''s a little more complicated than
that, but basically, you want to bind your server to the server socket and
set it to Listen. Then your clients will Connect to the server socket to
interact with the server application. The server calls Accept for each
client that it wants to accept when they attempt to connect. Each client
will have its own IPEndPoint, which is made up of an IP address and a Port.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

A lifetime is made up of
Lots of short moments.

"DaTurk" <mm******@hotmail.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
感谢您的回应,但您对员工到底是什么意思,并且
连接。我想我要问的是有什么区别,什么时候你想用另一个,什么情况。

此时我正在使用套接字创建一个多播套接字服务器设置,在我看到的例子中,发送的套接字通常连接,
和侦听绑定的套接字。
Thanks for the reponse, but what exactly do you mean by associate, and
connect. I guess what I''m asking is what is the difference, and when
would you want to use one over the other, what situations.

At this point I''m using sockets to create a multicast socket server
setup, and in examples I saw, the socket that sends typically connects,
and the socket that listens binds.



这篇关于套接字连接与绑定?有什么不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆