Hi friends i am new to socket programming in asp .net web application. I am trying to
create a socket (basically multicast/unicast socket) in my web application. If i create the socket on page load event i get the following error. Please tell me how to create
socket in such web applicatiion. Thank u all in advance.
Server Error in '/WebSite6' Application.
Only one usage of each socket address (protocol/network address/port) is normally permitted
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted
Source Error:
Line 23:
Line 24: IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 4321);Line 25: s.Bind(ipep); Line 26: IPAddress ip = IPAddress.Parse("226.1.1.1");
Line 27: s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, |
Source File: d:\WebS\WebSite6\Default.aspx.cs Line: 25
Stack Trace:
[SocketException (0x2740): Only one usage of each socket address (protocol/network address/port) is normally permitted] System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) +6124374 System.Net.Sockets.Socket.Bind(EndPoint localEP) +209 _Default.Page_Load(Object sender, EventArgs e) in d:\WebS\WebSite6\Default.aspx.cs:25 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +91 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207 |
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Sockets;
public partial class _Default : System.Web.UI.Page
{
byte[] databuffer = new byte[28];
int DataSize;
string raw;
public static Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
protected void Page_Load(object sender, EventArgs e)
{
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 4321);
s.Bind(ipep);
IPAddress ip = IPAddress.Parse("226.1.1.1");
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
new MulticastOption(ip, IPAddress.Any));
}
}