|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Asynchronous UDP Server not working..help pls????i tried creating a UDP Asynchronous Server.....but am getting errors and am not able to figure out why!!!......... here is the code........... *****************************code starts ******************** m_mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPHostEntry localHostEntry; localHostEntry = Dns.GetHostByName(Dns.GetHostName()); IPEndPoint ipLocal = new IPEndPoint(localHostEntry.AddressList[0], port); // Bind to local IP Address... m_mainSocket.Bind( ipLocal ); // Start listening... m_mainSocket.Listen(4); // Create the call back for any client connections... m_mainSocket.BeginAccept(new AsyncCallback (OnClientConnect), null); *****************************code ends here******************** The error message is... ATTEMPTED OPERATION IS NOT SUPPORTED FOR THE TYPE OF OBJECT REFERENCED what is this error regarding?.. i would be happy if someone could help me around... thanks in advance... with regards, C.C.Chakkaradeep Chakkaradeep wrote:
Show quote > Hi all, Accept() and Listen() are intended for use with TCP server sockets.> > i tried creating a UDP Asynchronous Server.....but am getting errors > and am not able to figure out why!!!......... > > here is the code........... > > *****************************code starts ******************** > m_mainSocket = new Socket(AddressFamily.InterNetwork, > SocketType.Dgram, > ProtocolType.Udp); > > IPHostEntry localHostEntry; > localHostEntry = Dns.GetHostByName(Dns.GetHostName()); > IPEndPoint ipLocal = new IPEndPoint(localHostEntry.AddressList[0], > port); > > // Bind to local IP Address... > m_mainSocket.Bind( ipLocal ); > // Start listening... > m_mainSocket.Listen(4); > // Create the call back for any client connections... > m_mainSocket.BeginAccept(new AsyncCallback (OnClientConnect), null); > *****************************code ends here******************** > > The error message is... > > ATTEMPTED OPERATION IS NOT SUPPORTED FOR THE TYPE OF OBJECT REFERENCED > > what is this error regarding?.. > > i would be happy if someone could help me around... You're using the wrong API ;-) For UDP applications, use ReceiveFrom() or BeginReceiveFrom(). Cheers, Hi,
thanks for the reply..am a newbie in this stuff.... now i have to tell EndReceiveFrom( ) to receive the data after being BeginReceive( )...will i get the remote end's ip address so that i can use it in SendTo( ) function?? with regards, C.C.Chakkaradeep Show quote "Joerg Jooss" wrote: > Chakkaradeep wrote: > > > Hi all, > > > > i tried creating a UDP Asynchronous Server.....but am getting errors > > and am not able to figure out why!!!......... > > > > here is the code........... > > > > *****************************code starts ******************** > > m_mainSocket = new Socket(AddressFamily.InterNetwork, > > SocketType.Dgram, > > ProtocolType.Udp); > > > > IPHostEntry localHostEntry; > > localHostEntry = Dns.GetHostByName(Dns.GetHostName()); > > IPEndPoint ipLocal = new IPEndPoint(localHostEntry.AddressList[0], > > port); > > > > // Bind to local IP Address... > > m_mainSocket.Bind( ipLocal ); > > // Start listening... > > m_mainSocket.Listen(4); > > // Create the call back for any client connections... > > m_mainSocket.BeginAccept(new AsyncCallback (OnClientConnect), null); > > *****************************code ends here******************** > > > > The error message is... > > > > ATTEMPTED OPERATION IS NOT SUPPORTED FOR THE TYPE OF OBJECT REFERENCED > > > > what is this error regarding?.. > > > > i would be happy if someone could help me around... > > Accept() and Listen() are intended for use with TCP server sockets. > You're using the wrong API ;-) > > For UDP applications, use ReceiveFrom() or BeginReceiveFrom(). > > Cheers, > -- > http://www.joergjooss.de > mailto:news-re***@joergjooss.de > Chakkaradeep wrote:
> Hi, Sure:> > thanks for the reply..am a newbie in this stuff.... > > now i have to tell EndReceiveFrom( ) to receive the data after being > BeginReceive( )...will i get the remote end's ip address so that i > can use it in SendTo( ) function?? public IAsyncResult BeginReceiveFrom( byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback callback, object state ); Note the EndPoint ref parameter. This will hold a reference to the remote EndPoint that sends datagrams to your server socket. Cheers, |
|||||||||||||||||||||||