|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
UDP socket with multiple portsI'm having some trouble creating an UDP socket that can listen on multiple ports. This is my code so far, it might give you a better idea of what I am trying to accomplish. The problem using this code is when the Bind is called I get a SocketException because the socket is already bound. this.udpSocket = new Socket( AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp ); this.udpSocket.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1 ); this.udpSocket.Bind( new IPEndPoint( IPAddress.Any, 7000 ) ); this.udpSocket.Bind( new IPEndPoint( IPAddress.Any, 7001 ) ); Any suggestions how to implement such a socket? Best regards, Robin Theilade A single socket can only be bound to one host/port pair.
-- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull Complex things are made up of lots of simple things. "Robin Theilade" <nospam.robin.theilade.nospam@nospam.gmail.com> wrote in message news:DqWag.37$vJ7.14@news.get2net.dk... > Hello, > > I'm having some trouble creating an UDP socket that can listen on multiple > ports. > > This is my code so far, it might give you a better idea of what I am > trying to accomplish. The problem using this code is when the Bind is > called I get a SocketException because the socket is already bound. > > this.udpSocket = new Socket( AddressFamily.InterNetwork, SocketType.Dgram, > ProtocolType.Udp ); > > this.udpSocket.SetSocketOption( SocketOptionLevel.Socket, > SocketOptionName.ReuseAddress, 1 ); > > this.udpSocket.Bind( new IPEndPoint( IPAddress.Any, 7000 ) ); > > this.udpSocket.Bind( new IPEndPoint( IPAddress.Any, 7001 ) ); > > > > Any suggestions how to implement such a socket? > > > > Best regards, > > Robin Theilade > > Yes that's whats troubling me. So the solution is either to set the Socket
to listen to every port (IP raw mode) or just one? There aren't any class that handles the listening from multiple ports, doesn't have to be Socket class. Best regards, Robin Theilade Show quote "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message news:uygfo7leGHA.3456@TK2MSFTNGP05.phx.gbl... >A single socket can only be bound to one host/port pair. > > -- > HTH, > > Kevin Spencer > Microsoft MVP > Professional Numbskull > > Complex things are made up of > lots of simple things. > > "Robin Theilade" <nospam.robin.theilade.nospam@nospam.gmail.com> wrote in > message news:DqWag.37$vJ7.14@news.get2net.dk... >> Hello, >> >> I'm having some trouble creating an UDP socket that can listen on >> multiple ports. >> >> This is my code so far, it might give you a better idea of what I am >> trying to accomplish. The problem using this code is when the Bind is >> called I get a SocketException because the socket is already bound. >> >> this.udpSocket = new Socket( AddressFamily.InterNetwork, >> SocketType.Dgram, ProtocolType.Udp ); >> >> this.udpSocket.SetSocketOption( SocketOptionLevel.Socket, >> SocketOptionName.ReuseAddress, 1 ); >> >> this.udpSocket.Bind( new IPEndPoint( IPAddress.Any, 7000 ) ); >> >> this.udpSocket.Bind( new IPEndPoint( IPAddress.Any, 7001 ) ); >> >> >> >> Any suggestions how to implement such a socket? >> >> >> >> Best regards, >> >> Robin Theilade >> >> > > Hello, Robin!
> Yes that's whats troubling me. So the solution is either to set the Socket AFAIK there is no such class. You can develop your own ( it will aggregate multiple sockets, socket per port... ).> to listen to every port (IP raw mode) or just one? There aren't any class > that handles the listening from multiple ports, doesn't have to be Socket > class. Usage of raw sockets is constained under XP SP2. Why do you need such functionality? What task you want to accomplish with multiport solution? Hi Vadym,
If Ethereal can sniff traffic in raw mode it should be possible somehow on a XP SP2, maybe I should try the WinPCap library Ethereal uses. Anyway, the reason why I need to receive data from more than one UDP port is that I want to build a mod for SA-MP (Grand Theft Auto - San Andreas - Multiplayer) and it used both 7777 and 7778 and maybe some more. The mod must be implemented as a proxy between the client and the server. Maybe I should look into the DirectX library, it's very normal for network games to use UDP and often multiple when it's a Microsoft game. Best regards, Robin Theilade Show quote "Vadym Stetsyak" <vady***@ukr.net> wrote in message news:%23zjQi5meGHA.5040@TK2MSFTNGP03.phx.gbl... > Hello, Robin! > >> Yes that's whats troubling me. So the solution is either to set the >> Socket >> to listen to every port (IP raw mode) or just one? There aren't any class >> that handles the listening from multiple ports, doesn't have to be Socket >> class. > > AFAIK there is no such class. You can develop your own ( it will aggregate > multiple sockets, socket per port... ). > Usage of raw sockets is constained under XP SP2. > > Why do you need such functionality? What task you want to accomplish with > multiport solution? > -- > Regards, Vadym Stetsyak > www: http://vadmyst.blogspot.com Hello, Robin!
RT> Anyway, the reason why I need to receive data from more than one UDP RT> port is that I want to build a mod for SA-MP (Grand Theft Auto - San RT> Andreas - Multiplayer) and it used both 7777 and 7778 and maybe some RT> more. The mod must be implemented as a proxy between the client and the RT> server. Maybe I should look into the DirectX library, it's very normal RT> for network games to use UDP and often multiple when it's a Microsoft RT> game. Network "sniffing" approach is not what you want. The option for you is to develop a custom class that will aggregate several sockets to simulate multiport messaging. DirectX has DirectPlay technology that is used for network communication. ( http://en.wikipedia.org/wiki/DirectPlay ) ( http://www.informit.com/articles/article.asp?p=26236 ) Hi Vadym,
I'll take a look at DirectPlay and if it doesn't have build in support for multiple ports in one host object, I'll implement my own. Thanks for the help. Best regards, Robin Theilade Show quote "Vadym Stetsyak" <vady***@ukr.net> wrote in message news:eOd%23yWneGHA.536@TK2MSFTNGP02.phx.gbl... > Hello, Robin! > > RT> Anyway, the reason why I need to receive data from more than one UDP > RT> port is that I want to build a mod for SA-MP (Grand Theft Auto - San > RT> Andreas - Multiplayer) and it used both 7777 and 7778 and maybe some > RT> more. The mod must be implemented as a proxy between the client and > the > RT> server. Maybe I should look into the DirectX library, it's very normal > RT> for network games to use UDP and often multiple when it's a Microsoft > RT> game. > > Network "sniffing" approach is not what you want. > > The option for you is to develop a custom class that will aggregate > several sockets to simulate multiport messaging. > > DirectX has DirectPlay technology that is used for network communication. > ( http://en.wikipedia.org/wiki/DirectPlay ) > ( http://www.informit.com/articles/article.asp?p=26236 ) > > > > -- > Regards, Vadym Stetsyak > www: http://vadmyst.blogspot.com Keep in mind that a Socket, by definition, represents a single unique
address, which is the combination of an IP address (which has 65536 ports) and a port number. So, if you use Sockets, MS or otherwise, you're limited to one port per Socket. -- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull The man who questions opinions is wise. The man who quarrels with facts is a fool. "Robin Theilade" <nospam.robin.theilade.nospam@nospam.gmail.com> wrote in message news:F3_ag.86$0I3.21@news.get2net.dk... > Hi Vadym, > > I'll take a look at DirectPlay and if it doesn't have build in support for > multiple ports in one host object, I'll implement my own. > > Thanks for the help. > > Best regards, > Robin Theilade > > "Vadym Stetsyak" <vady***@ukr.net> wrote in message > news:eOd%23yWneGHA.536@TK2MSFTNGP02.phx.gbl... >> Hello, Robin! >> >> RT> Anyway, the reason why I need to receive data from more than one UDP >> RT> port is that I want to build a mod for SA-MP (Grand Theft Auto - San >> RT> Andreas - Multiplayer) and it used both 7777 and 7778 and maybe some >> RT> more. The mod must be implemented as a proxy between the client and >> the >> RT> server. Maybe I should look into the DirectX library, it's very >> normal >> RT> for network games to use UDP and often multiple when it's a Microsoft >> RT> game. >> >> Network "sniffing" approach is not what you want. >> >> The option for you is to develop a custom class that will aggregate >> several sockets to simulate multiport messaging. >> >> DirectX has DirectPlay technology that is used for network communication. >> ( http://en.wikipedia.org/wiki/DirectPlay ) >> ( http://www.informit.com/articles/article.asp?p=26236 ) >> >> >> >> -- >> Regards, Vadym Stetsyak >> www: http://vadmyst.blogspot.com > > Hi Kevin,
You're right about that, but still it is not unusual that someone builds some kind of proxy and my guess was that the .NET framework already such a class to handle multiple ports. Consider the opposite case where you have serveral clients; here the Socket class supports multicast to send the same data to all the clients. I know that it is not interely the same but it proves that the Socket class in special cases can handle multiple addresses. So it was just a small hope. Best regards, Robin Theilade Show quote "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message news:emgskQoeGHA.4276@TK2MSFTNGP03.phx.gbl... > Keep in mind that a Socket, by definition, represents a single unique > address, which is the combination of an IP address (which has 65536 ports) > and a port number. So, if you use Sockets, MS or otherwise, you're limited > to one port per Socket. > > -- > HTH, > > Kevin Spencer > Microsoft MVP > Professional Numbskull > > The man who questions opinions is wise. > The man who quarrels with facts is a fool. > > "Robin Theilade" <nospam.robin.theilade.nospam@nospam.gmail.com> wrote in > message news:F3_ag.86$0I3.21@news.get2net.dk... >> Hi Vadym, >> >> I'll take a look at DirectPlay and if it doesn't have build in support >> for multiple ports in one host object, I'll implement my own. >> >> Thanks for the help. >> >> Best regards, >> Robin Theilade >> >> "Vadym Stetsyak" <vady***@ukr.net> wrote in message >> news:eOd%23yWneGHA.536@TK2MSFTNGP02.phx.gbl... >>> Hello, Robin! >>> >>> RT> Anyway, the reason why I need to receive data from more than one >>> UDP >>> RT> port is that I want to build a mod for SA-MP (Grand Theft Auto - San >>> RT> Andreas - Multiplayer) and it used both 7777 and 7778 and maybe some >>> RT> more. The mod must be implemented as a proxy between the client and >>> the >>> RT> server. Maybe I should look into the DirectX library, it's very >>> normal >>> RT> for network games to use UDP and often multiple when it's a >>> Microsoft >>> RT> game. >>> >>> Network "sniffing" approach is not what you want. >>> >>> The option for you is to develop a custom class that will aggregate >>> several sockets to simulate multiport messaging. >>> >>> DirectX has DirectPlay technology that is used for network >>> communication. >>> ( http://en.wikipedia.org/wiki/DirectPlay ) >>> ( http://www.informit.com/articles/article.asp?p=26236 ) >>> >>> >>> >>> -- >>> Regards, Vadym Stetsyak >>> www: http://vadmyst.blogspot.com >> >> > > Hello, Robin!
RT> You're right about that, but still it is not unusual that someone RT> builds some kind of proxy and my guess was that the .NET framework RT> already such a class to handle multiple ports. Consider the RT> opposite case where you have serveral clients; here the Socket class RT> supports multicast to send the same data to all the clients. I know RT> that it is not interely the same but it proves that the Socket class in RT> special cases can handle multiple addresses. So it was just a small RT> hope. Actually multicasting is also happening on single address, multicast address :8-). So, there is still host/port couple out there. Hi Vadym,
You're probably right about that. I was going to lookup the DirectPlay you mentioned when I found this FAQ entry http://www.thezbuffer.com/articles/387.aspx. I guess I'll have to go with the multiple sockets solution. Thanks for the help. Best regards, Robin Theilade Show quote "Vadym Stetsyak" <vady***@ukr.net> wrote in message news:eFdvtDpeGHA.3484@TK2MSFTNGP02.phx.gbl... > Hello, Robin! > > RT> You're right about that, but still it is not unusual that someone > RT> builds some kind of proxy and my guess was that the .NET framework > RT> already such a class to handle multiple ports. Consider the > RT> opposite case where you have serveral clients; here the Socket class > RT> supports multicast to send the same data to all the clients. I know > RT> that it is not interely the same but it proves that the Socket class > in > RT> special cases can handle multiple addresses. So it was just a small > RT> hope. > > Actually multicasting is also happening on single address, multicast > address :8-). So, there is still > host/port couple out there. > > -- > Regards, Vadym Stetsyak > www: http://vadmyst.blogspot.com Here's a great MSDN article about setting up a reliable UDP broadcast (using
only one port for many clients): http://msdn.microsoft.com/msdnmag/issues/06/02/UDP/ -- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull The man who questions opinions is wise. The man who quarrels with facts is a fool. "Robin Theilade" <nospam.robin.theilade.nospam@nospam.gmail.com> wrote in message news:SNebg.12$%J5.1@news.get2net.dk... > Hi Vadym, > > You're probably right about that. > > I was going to lookup the DirectPlay you mentioned when I found this FAQ > entry http://www.thezbuffer.com/articles/387.aspx. I guess I'll have to go > with the multiple sockets solution. > > Thanks for the help. > > Best regards, > Robin Theilade > > "Vadym Stetsyak" <vady***@ukr.net> wrote in message > news:eFdvtDpeGHA.3484@TK2MSFTNGP02.phx.gbl... >> Hello, Robin! >> >> RT> You're right about that, but still it is not unusual that someone >> RT> builds some kind of proxy and my guess was that the .NET framework >> RT> already such a class to handle multiple ports. Consider the >> RT> opposite case where you have serveral clients; here the Socket class >> RT> supports multicast to send the same data to all the clients. I know >> RT> that it is not interely the same but it proves that the Socket class >> in >> RT> special cases can handle multiple addresses. So it was just a small >> RT> hope. >> >> Actually multicasting is also happening on single address, multicast >> address :8-). So, there is still >> host/port couple out there. >> >> -- >> Regards, Vadym Stetsyak >> www: http://vadmyst.blogspot.com > > Hi Kevin,
That article looks interesting, thanks! Best regards, Robin Theilade Show quote "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> wrote in message news:O4dJQZzeGHA.2456@TK2MSFTNGP04.phx.gbl... > Here's a great MSDN article about setting up a reliable UDP broadcast > (using only one port for many clients): > > http://msdn.microsoft.com/msdnmag/issues/06/02/UDP/ > > -- > HTH, > > Kevin Spencer > Microsoft MVP > Professional Numbskull > > The man who questions opinions is wise. > The man who quarrels with facts is a fool. > > "Robin Theilade" <nospam.robin.theilade.nospam@nospam.gmail.com> wrote in > message news:SNebg.12$%J5.1@news.get2net.dk... >> Hi Vadym, >> >> You're probably right about that. >> >> I was going to lookup the DirectPlay you mentioned when I found this FAQ >> entry http://www.thezbuffer.com/articles/387.aspx. I guess I'll have to >> go with the multiple sockets solution. >> >> Thanks for the help. >> >> Best regards, >> Robin Theilade >> >> "Vadym Stetsyak" <vady***@ukr.net> wrote in message >> news:eFdvtDpeGHA.3484@TK2MSFTNGP02.phx.gbl... >>> Hello, Robin! >>> >>> RT> You're right about that, but still it is not unusual that someone >>> RT> builds some kind of proxy and my guess was that the .NET framework >>> RT> already such a class to handle multiple ports. Consider the >>> RT> opposite case where you have serveral clients; here the Socket class >>> RT> supports multicast to send the same data to all the clients. I know >>> RT> that it is not interely the same but it proves that the Socket class >>> in >>> RT> special cases can handle multiple addresses. So it was just a small >>> RT> hope. >>> >>> Actually multicasting is also happening on single address, multicast >>> address :8-). So, there is still >>> host/port couple out there. >>> >>> -- >>> Regards, Vadym Stetsyak >>> www: http://vadmyst.blogspot.com >> >> > > Why not use two sockets??
-- Show quoteWilliam Stacey [MVP] "Robin Theilade" <nospam.robin.theilade.nospam@nospam.gmail.com> wrote in message news:DqWag.37$vJ7.14@news.get2net.dk... | Hello, | | I'm having some trouble creating an UDP socket that can listen on multiple | ports. | | This is my code so far, it might give you a better idea of what I am trying | to accomplish. The problem using this code is when the Bind is called I get | a SocketException because the socket is already bound. | | this.udpSocket = new Socket( AddressFamily.InterNetwork, SocketType.Dgram, | ProtocolType.Udp ); | | this.udpSocket.SetSocketOption( SocketOptionLevel.Socket, | SocketOptionName.ReuseAddress, 1 ); | | this.udpSocket.Bind( new IPEndPoint( IPAddress.Any, 7000 ) ); | | this.udpSocket.Bind( new IPEndPoint( IPAddress.Any, 7001 ) ); | | | | Any suggestions how to implement such a socket? | | | | Best regards, | | Robin Theilade | | Hi William,
It is the solution that I have now, except that I have four sockets two for each way through my proxy. But it seems a bit like I would be abusing my computers resources if I had to bould a proxy that took every port from 1 to 1024. It would mean that I had to use 2048 sockets. But thats the only way, theres nothing to do about it. Best regards, Robin Theilade Show quote "William Stacey [MVP]" <william.sta***@gmail.com> wrote in message news:ep8VDIveGHA.4912@TK2MSFTNGP05.phx.gbl... > Why not use two sockets?? > > -- > William Stacey [MVP] > > "Robin Theilade" <nospam.robin.theilade.nospam@nospam.gmail.com> wrote in > message news:DqWag.37$vJ7.14@news.get2net.dk... > | Hello, > | > | I'm having some trouble creating an UDP socket that can listen on > multiple > | ports. > | > | This is my code so far, it might give you a better idea of what I am > trying > | to accomplish. The problem using this code is when the Bind is called I > get > | a SocketException because the socket is already bound. > | > | this.udpSocket = new Socket( AddressFamily.InterNetwork, > SocketType.Dgram, > | ProtocolType.Udp ); > | > | this.udpSocket.SetSocketOption( SocketOptionLevel.Socket, > | SocketOptionName.ReuseAddress, 1 ); > | > | this.udpSocket.Bind( new IPEndPoint( IPAddress.Any, 7000 ) ); > | > | this.udpSocket.Bind( new IPEndPoint( IPAddress.Any, 7001 ) ); > | > | > | > | Any suggestions how to implement such a socket? > | > | > | > | Best regards, > | > | Robin Theilade > | > | > > |
|||||||||||||||||||||||