Hi.
I have some quite unusual situation at which SocketException is thown while
connecting a socket. Generally the aim of application is processes data and
send results to a specified IPEndPoint. Since theres small amount of time
for processing and sending large amount of data it is logical to split whole
process in to few threads. One thread processes data and other sends it. The
problem occures when user sets too little time for doing that.
At first the thread works fine for about a minute or two, results are being
received on another machine event when the speed of whole process is
considered to be critical. And then just like that, exception
SocketException is thrown while connecting to an IpEndPoint with message
that might be translated as "It is usually allowed a single use of socket
address". As seen below socket is being shutdown and closed in the end. And
it seems like theres absolutely no reason for that exception to catch. Any
propositions? Thank you.
Error code of exception is 10048
private void Operate()
{
while (/*There is data to send*/)
{
Socket socket = null;
try
{
socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
socket.Connect(ipEndPoint);
<--------------------------------------------------------------------------Exception:
SocketException thrown here !!!!!!!!!!!!!
NetworkStream stream = new NetworkStream(socket);
BinaryWriter writer = new BinaryWriter(stream);
Scan[] scans = null;
lock (queue)
{
scans = queue.Dequeue() as Scan[];
}
for (int i = 0; i < scans.Length; i++)
{
writer.Write(scans[i].Azimuth);
socket.Send(scans[i].Data);
}
if (socket.Connected)
{
socket.Shutdown(SocketShutdown.Both);
}
}
catch (SocketException e)
{
msp.Engine.Paused = true;
if (MessageBox.Show(msp.Window,"Error occured:\n" + e.ToString()
+ "\n\nStop process?","Warning",MessageBoxButtons.YesNo) ==
DialogResult.Yes)
{
msp.Engine.Launched = false;
}
else
{
msp.Engine.Paused = false;
}
}
finally
{
if (socket != null)
{
socket.Close();
}
}
}