[ENet-discuss] How can I get the client port created in my client side
Ruud van Gaal
ruud at racer.nl
Fri Jul 13 12:23:32 PDT 2012
The tutorial on http://enet.bespin.org/Tutorial.html has 1 server that
accepts 32 clients.
It's really standard behavior; any server is often meant to deal with
multiple clients. Just run the server, then run 2 clients (perhaps they
need to be on separate PC's though).
Ruud
On Fri, Jul 13, 2012 at 8:02 PM, Siqi Shen <siqishen at gmail.com> wrote:
> Thanks for reply.
>
> The host->socket is the socket number that assigned by the OS.
> So when I use
> "
> sockaddr_in a;
> int size = sizeof(a);
> getsockname(m_Host->socket, (LPSOCKADDR) &a, &size);
> cout<<"The port i get "<< ntohs(a.sin_port)<<std::endl;
> "
> when connection event was receive in client, I can get the port number. I
> can not get the port number when host was created.
>
>
> To Soren, what I want to do is debugging and understanding whether my
> network protocol is correctly.
> You mentioned that Enet can multiplex a port thus able to communicate with
> multiple host. This is very interesting, can you show a example of this
> code?
>
> Thanks and best regards,
> Siqi
>
> 2012/7/12 <enet-discuss-request at cubik.org>
>
>> Send ENet-discuss mailing list submissions to
>> enet-discuss at cubik.org
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>> or, via email, send a message with subject or body 'help' to
>> enet-discuss-request at cubik.org
>>
>> You can reach the person managing the list at
>> enet-discuss-owner at cubik.org
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of ENet-discuss digest..."
>>
>>
>> Today's Topics:
>>
>> 1. Re: How can I get the client port created in my client side
>> (Daniel Aquino)
>> 2. Re: How can I get the client port created in my client side
>> (Soren Dreijer) (Siqi Shen)
>> 3. Re: How can I get the client port created in my client
>> side
>> (Soren Dreijer) (Soren Dreijer)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Wed, 11 Jul 2012 14:49:40 -0400
>> From: Daniel Aquino <mr.danielaquino at gmail.com>
>> To: Discussion of the ENet library <enet-discuss at cubik.org>
>> Subject: Re: [ENet-discuss] How can I get the client port created in
>> my client side
>> Message-ID:
>> <CACRDGdkpKRcnV61P-eoJoyj-Ft8Tan4ObUCbHK=
>> 113wqDfegeg at mail.gmail.com>
>> Content-Type: text/plain; charset="windows-1252"
>>
>> You can find out that information from enet_host->socket.
>>
>>
>> On Wed, Jul 11, 2012 at 9:04 AM, Soren Dreijer <dreijer at echobit.net>
>> wrote:
>>
>> > You?re using UDP and you therefore don?t have separate client-side ports
>> > when you ?connect? to a server.****
>> >
>> > ** **
>> >
>> > The port you?re using on the client is the one you specified in
>> > enet_host_create() when you initialized enet.****
>> >
>> > ** **
>> >
>> > *From:* enet-discuss-bounces at cubik.org [mailto:
>> > enet-discuss-bounces at cubik.org] *On Behalf Of *Siqi Shen
>> > *Sent:* Wednesday, July 11, 2012 6:49 AM
>> > *To:* enet-discuss at cubik.org
>> > *Subject:* [ENet-discuss] How can I get the client port created in my
>> > client side****
>> >
>> > ** **
>> >
>> > Hi All, ****
>> >
>> > ** **
>> >
>> > I am developing a small game using enet as network layer. My question is
>> > that how can I know the port I created in my client side to connect to
>> > remote host. I know that I can know the client's port in server's side
>> when
>> > ENET_EVENT_TYPE_CONNECT receive; but I can not get the port when I use
>> > enet_host_create or enet_host_connect or ENET_EVENT_TYPE_CONNECT
>> receive in
>> > client's side. Anyone know how to deal with this problem? ****
>> >
>> > ** **
>> >
>> > Thanks and best regards,****
>> >
>> > Siqi****
>> >
>> > _______________________________________________
>> > ENet-discuss mailing list
>> > ENet-discuss at cubik.org
>> > http://lists.cubik.org/mailman/listinfo/enet-discuss
>> >
>> >
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <
>> http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/7be08d1a/attachment-0001.html
>> >
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Thu, 12 Jul 2012 11:24:23 +0200
>> From: Siqi Shen <siqishen at gmail.com>
>> To: enet-discuss at cubik.org
>> Subject: Re: [ENet-discuss] How can I get the client port created in
>> my client side (Soren Dreijer)
>> Message-ID:
>> <CAD6PKm30kP=
>> gwTexMsqeeR3GxjjcjVTV6ua9YzhQ79WLKh90LA at mail.gmail.com>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> Thanks for your reply. Setting port in enet_host_create is not flexible
>> enough, as I may create more than 20 processes/threads. I think that once
>> a udp diagram has been setup ( sendto() function has been called), the udp
>> port in the client side is determine and it will be consistent across the
>> whole application if we don't change the port manually.
>>
>> As I am using Win7 64bit. I use "netstat -an -p udp -o" to get the udp
>> port
>> and process id mapping and find that the UDP port I created in my process
>> through enet is consistent. And as described in MSDN
>> "http://msdn.microsoft.com/en-us/library/ms740148%28VS.85%29.aspx" that
>> "If
>> a socket is opened, a
>> *setsockopt*<
>> http://msdn.microsoft.com/en-us/library/ms740476(v=vs.85).aspx>
>> call
>> is made, and then a *sendto* call is made, Windows Sockets performs an
>> implicit *bind* function call."
>> so we can get the port through
>> "*getsockname*<
>> http://msdn.microsoft.com/en-us/library/ms738543(v=vs.85).aspx>
>> " function. But I can not get the port in enet (I want to use the port
>> number for debugging). Do you have a better solution besides setting
>> port manually?
>>
>>
>> 2012/7/11 <enet-discuss-request at cubik.org>
>>
>> > Send ENet-discuss mailing list submissions to
>> > enet-discuss at cubik.org
>> >
>> > To subscribe or unsubscribe via the World Wide Web, visit
>> > http://lists.cubik.org/mailman/listinfo/enet-discuss
>> > or, via email, send a message with subject or body 'help' to
>> > enet-discuss-request at cubik.org
>> >
>> > You can reach the person managing the list at
>> > enet-discuss-owner at cubik.org
>> >
>> > When replying, please edit your Subject line so it is more specific
>> > than "Re: Contents of ENet-discuss digest..."
>> >
>> >
>> > Today's Topics:
>> >
>> > 1. How can I get the client port created in my client side
>> > (Siqi Shen)
>> > 2. Re: How can I get the client port created in my client side
>> > (Soren Dreijer)
>> >
>> >
>> > ----------------------------------------------------------------------
>> >
>> > Message: 1
>> > Date: Wed, 11 Jul 2012 13:48:44 +0200
>> > From: Siqi Shen <siqishen at gmail.com>
>> > To: enet-discuss at cubik.org
>> > Subject: [ENet-discuss] How can I get the client port created in my
>> > client side
>> > Message-ID:
>> > <
>> > CAD6PKm0KJqwY-Rf5rSeBOL3ru7x7c2jEyxYvRCAExD1QrecMrQ at mail.gmail.com>
>> > Content-Type: text/plain; charset="iso-8859-1"
>> >
>> > Hi All,
>> >
>> > I am developing a small game using enet as network layer. My question is
>> > that how can I know the port I created in my client side to connect to
>> > remote host. I know that I can know the client's port in server's side
>> when
>> > ENET_EVENT_TYPE_CONNECT receive; but I can not get the port when I use
>> > enet_host_create or enet_host_connect or ENET_EVENT_TYPE_CONNECT
>> receive in
>> > client's side. Anyone know how to deal with this problem?
>> >
>> > Thanks and best regards,
>> > Siqi
>> > -------------- next part --------------
>> > An HTML attachment was scrubbed...
>> > URL: <
>> >
>> http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/c64afa88/attachment-0001.html
>> > >
>> >
>> > ------------------------------
>> >
>> > Message: 2
>> > Date: Wed, 11 Jul 2012 08:04:40 -0500
>> > From: "Soren Dreijer" <dreijer at echobit.net>
>> > To: "'Discussion of the ENet library'" <enet-discuss at cubik.org>
>> > Subject: Re: [ENet-discuss] How can I get the client port created in
>> > my client side
>> > Message-ID: <011301cd5f65$bc210a70$34631f50$@echobit.net>
>> > Content-Type: text/plain; charset="us-ascii"
>> >
>> > You're using UDP and you therefore don't have separate client-side ports
>> > when you "connect" to a server.
>> >
>> >
>> >
>> > The port you're using on the client is the one you specified in
>> > enet_host_create() when you initialized enet.
>> >
>> >
>> >
>> > From: enet-discuss-bounces at cubik.org [mailto:
>> > enet-discuss-bounces at cubik.org]
>> > On Behalf Of Siqi Shen
>> > Sent: Wednesday, July 11, 2012 6:49 AM
>> > To: enet-discuss at cubik.org
>> > Subject: [ENet-discuss] How can I get the client port created in my
>> client
>> > side
>> >
>> >
>> >
>> > Hi All,
>> >
>> >
>> >
>> > I am developing a small game using enet as network layer. My question is
>> > that how can I know the port I created in my client side to connect to
>> > remote host. I know that I can know the client's port in server's side
>> when
>> > ENET_EVENT_TYPE_CONNECT receive; but I can not get the port when I use
>> > enet_host_create or enet_host_connect or ENET_EVENT_TYPE_CONNECT
>> receive in
>> > client's side. Anyone know how to deal with this problem?
>> >
>> >
>> >
>> > Thanks and best regards,
>> >
>> > Siqi
>> >
>> > -------------- next part --------------
>> > An HTML attachment was scrubbed...
>> > URL: <
>> >
>> http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/8830cb5d/attachment-0001.html
>> > >
>> >
>> > ------------------------------
>> >
>> > _______________________________________________
>> > ENet-discuss mailing list
>> > ENet-discuss at cubik.org
>> > http://lists.cubik.org/mailman/listinfo/enet-discuss
>> >
>> >
>> > End of ENet-discuss Digest, Vol 109, Issue 1
>> > ********************************************
>> >
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <
>> http://lists.cubik.org/pipermail/enet-discuss/attachments/20120712/1c9754e4/attachment-0001.html
>> >
>>
>> ------------------------------
>>
>> Message: 3
>> Date: Thu, 12 Jul 2012 07:57:22 -0500
>> From: "Soren Dreijer" <dreijer at echobit.com>
>> To: "'Discussion of the ENet library'" <enet-discuss at cubik.org>
>> Subject: Re: [ENet-discuss] How can I get the client port created in
>> my client side (Soren Dreijer)
>> Message-ID: <004401cd602d$e14b5da0$a3e218e0$@echobit.com>
>> Content-Type: text/plain; charset="us-ascii"
>>
>> I don't follow. Enet is only using a single port and multiplexes all
>> connections through that single port. That is, it doesn't matter whether
>> you're communicating with one or ten remote hosts; all traffic will go
>> through that one port that Enet is bound to.
>>
>>
>>
>> *You* are in charge of choosing the port when you set up Enet (i.e. call
>> enet_host_create), so I'm a little confused what the problem is. If you
>> create 20 Enet instances in 20 different processes, then they'd all have
>> different ports that you've chosen and thus know.
>>
>>
>>
>> Maybe if you described what you're really trying to achieve, I can better
>> understand. :)
>>
>>
>>
>> / Soren
>>
>>
>>
>> From: enet-discuss-bounces at cubik.org [mailto:
>> enet-discuss-bounces at cubik.org]
>> On Behalf Of Siqi Shen
>> Sent: Thursday, July 12, 2012 4:24 AM
>> To: enet-discuss at cubik.org
>> Subject: Re: [ENet-discuss] How can I get the client port created in my
>> client side (Soren Dreijer)
>>
>>
>>
>> Thanks for your reply. Setting port in enet_host_create is not flexible
>> enough, as I may create more than 20 processes/threads. I think that
>> once a
>> udp diagram has been setup ( sendto() function has been called), the udp
>> port in the client side is determine and it will be consistent across the
>> whole application if we don't change the port manually.
>>
>>
>>
>> As I am using Win7 64bit. I use "netstat -an -p udp -o" to get the udp
>> port
>> and process id mapping and find that the UDP port I created in my process
>> through enet is consistent. And as described in MSDN
>>
>> "http://msdn.microsoft.com/en-us/library/ms740148%28VS.85%29.aspx" that
>> "If
>> a socket is opened, a
>> <http://msdn.microsoft.com/en-us/library/ms740476(v=vs.85).aspx>
>> setsockopt
>> call is made, and then a sendto call is made, Windows Sockets performs an
>> implicit bind function call."
>>
>> so we can get the port through "
>> <http://msdn.microsoft.com/en-us/library/ms738543(v=vs.85).aspx>
>> getsockname
>> " function. But I can not get the port in enet (I want to use the port
>> number for debugging). Do you have a better solution besides setting port
>> manually?
>>
>>
>>
>>
>>
>> 2012/7/11 <enet-discuss-request at cubik.org>
>>
>> Send ENet-discuss mailing list submissions to
>> enet-discuss at cubik.org
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>> or, via email, send a message with subject or body 'help' to
>> enet-discuss-request at cubik.org
>>
>> You can reach the person managing the list at
>> enet-discuss-owner at cubik.org
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of ENet-discuss digest..."
>>
>>
>> Today's Topics:
>>
>> 1. How can I get the client port created in my client side
>> (Siqi Shen)
>> 2. Re: How can I get the client port created in my client side
>> (Soren Dreijer)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Wed, 11 Jul 2012 13:48:44 +0200
>> From: Siqi Shen <siqishen at gmail.com>
>> To: enet-discuss at cubik.org
>> Subject: [ENet-discuss] How can I get the client port created in my
>> client side
>> Message-ID:
>> <
>> CAD6PKm0KJqwY-Rf5rSeBOL3ru7x7c2jEyxYvRCAExD1QrecMrQ at mail.gmail.com>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> Hi All,
>>
>> I am developing a small game using enet as network layer. My question is
>> that how can I know the port I created in my client side to connect to
>> remote host. I know that I can know the client's port in server's side
>> when
>> ENET_EVENT_TYPE_CONNECT receive; but I can not get the port when I use
>> enet_host_create or enet_host_connect or ENET_EVENT_TYPE_CONNECT receive
>> in
>> client's side. Anyone know how to deal with this problem?
>>
>> Thanks and best regards,
>> Siqi
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> <
>> http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/c64afa88
>> /attachment-0001.html<http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/c64afa88/attachment-0001.html>
>> >
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Wed, 11 Jul 2012 08:04:40 -0500
>> From: "Soren Dreijer" <dreijer at echobit.net>
>> To: "'Discussion of the ENet library'" <enet-discuss at cubik.org>
>> Subject: Re: [ENet-discuss] How can I get the client port created in
>> my client side
>> Message-ID: <011301cd5f65$bc210a70$34631f50$@echobit.net>
>> Content-Type: text/plain; charset="us-ascii"
>>
>> You're using UDP and you therefore don't have separate client-side ports
>> when you "connect" to a server.
>>
>>
>>
>> The port you're using on the client is the one you specified in
>> enet_host_create() when you initialized enet.
>>
>>
>>
>> From: enet-discuss-bounces at cubik.org [mailto:
>> enet-discuss-bounces at cubik.org]
>> On Behalf Of Siqi Shen
>> Sent: Wednesday, July 11, 2012 6:49 AM
>> To: enet-discuss at cubik.org
>> Subject: [ENet-discuss] How can I get the client port created in my client
>> side
>>
>>
>>
>> Hi All,
>>
>>
>>
>> I am developing a small game using enet as network layer. My question is
>> that how can I know the port I created in my client side to connect to
>> remote host. I know that I can know the client's port in server's side
>> when
>> ENET_EVENT_TYPE_CONNECT receive; but I can not get the port when I use
>> enet_host_create or enet_host_connect or ENET_EVENT_TYPE_CONNECT receive
>> in
>> client's side. Anyone know how to deal with this problem?
>>
>>
>>
>> Thanks and best regards,
>>
>> Siqi
>>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> <
>> http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/8830cb5d
>> /attachment-0001.html<http://lists.cubik.org/pipermail/enet-discuss/attachments/20120711/8830cb5d/attachment-0001.html>
>> >
>>
>> ------------------------------
>>
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>
>>
>> End of ENet-discuss Digest, Vol 109, Issue 1
>> ********************************************
>>
>>
>>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <
>> http://lists.cubik.org/pipermail/enet-discuss/attachments/20120712/312ce901/attachment.html
>> >
>>
>> ------------------------------
>>
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>
>>
>> End of ENet-discuss Digest, Vol 109, Issue 2
>> ********************************************
>>
>
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20120713/873e678e/attachment-0001.html>
More information about the ENet-discuss
mailing list