When I run the program it says:
"System.Net.Sockets.SocketException: "Normally, each socket address (protocol, network address, or port) may only be used once"
It shows an error here:
socketCmdText = new UdpClient(cmdTextPort);
-The socketCmdText is also has a value of null
This is my code:
UdpClient socketCmd;
UdpClient socketCmdText;
private const int cmdTextPort = 6666;
private const int cmdPort = 6676;
private double tempSensTop = 0;
private double tempSensBottom = 0;
private double tempProcessor = 0;
private String firmware = "";
private String streamType = "";
private String camIP = "";
public override void initializeJob()
{
if (TempDevice == temperatureGauge.udp)
{
camIP = parameters[0];
socketCmdText = new UdpClient(cmdTextPort);
socketCmdText.BeginReceive(new AsyncCallback(OnUdpDataCmdText), socketCmdText);
socketCmd = new UdpClient(cmdPort);
socketCmdText.BeginReceive(new AsyncCallback(OnUdpDataCmd), socketCmd);
}
}
This is where Im sending:
private void requestData()
{
IPAddress _camip = IPAddress.Parse(camIP);
IPEndPoint _ep = new IPEndPoint(_camip, cmdTextPort);
byte[] _sendbuf = Encoding.ASCII.GetBytes("Cmd_ISL_GetCurrentSensorTemperature");
socketCmdText.Send(_sendbuf, _sendbuf.Length, _ep);
byte[] _sendbuf2 = Encoding.ASCII.GetBytes("Get_Temp");
socketCmdText.Send(_sendbuf2, _sendbuf2.Length, _ep);
}
void OnUdpDataCmdText(IAsyncResult result)
{
try
{
UdpClient socket = result.AsyncState as UdpClient;
IPEndPoint source = new IPEndPoint(IPAddress.Any, cmdTextPort);
byte[] message = socket.EndReceive(result, ref source);
socket.BeginReceive(new AsyncCallback(OnUdpDataCmdText), socket);
}
catch (Exception e)
{
Console.WriteLine("Error TemperatureMesurement-Job OnUdpDataCmdTxt " + jobName + " : " + e.Message);
}
}
void OnUdpDataCmd(IAsyncResult result)
{
try
{
UdpClient socket = result.AsyncState as UdpClient;
IPEndPoint source = new IPEndPoint(IPAddress.Any, cmdPort);
byte[] message = socket.EndReceive(result, ref source);
string[] receiveString = BitConverter.ToString(message).Split('-');
if (camIP == source.Address.ToString())
{
if (string.Concat(receiveString).Substring(0, 16) == "0201001001000002")
{
streamType = receiveString[8] + receiveString[9];
}
}
socket.BeginReceive(new AsyncCallback(OnUdpDataCmd), socket);
}
catch (Exception e)
{
Console.WriteLine("Error TemperatureMesurement-Job OnUdpDataCmd " + jobName + " : " + e.Message);
}
}
What I have tried:
Any help will be appreciated. Trying since a long time to get rid of the problem, i tried using another port, closing it in task manager but it doesnt seem to work. But it doesnt