Hello!
I am building a pubnub client on fez cobra. Everything works ok for the first time, but then, if I cancel listener for the pubnub channel
and relaunch it, I am getting socket error with code 10038 indefenitely … for it to work again, I have to restart the whole app.
I am using ethernet for internet connection.
I found some posts about that error on this forum, but no solution was given.
The error code reads as following:
[quote]Socket operation on nonsocket.
An operation was attempted on something that is not a socket. Either the socket handle parameter did not reference a valid socket, or for select, a member of an fd_set was not valid.[/quote]
I have no clue what does that mean whatsoever :S
And here is the code for the listener thread …
private void ChannelListener(object channelSettings)
{
var channel = (ChannelSubscription) channelSettings;
channel.Status = Status.Running;
var ct = channel.CancellationToken;
string timetoken = "0";
var urlComponents = new ArrayList {"subscribe", this.subscribeKey, channel.Name, "0", timetoken};
while (true)
{
try
{
urlComponents[4] = timetoken;
var url = this.BuildAndEncodeUrl(urlComponents);
var request = (HttpWebRequest) WebRequest.Create(url);
request.KeepAlive = true;
request.Timeout = 200000;
request.ReadWriteTimeout = 200000;
ct.Register(request.Dispose);
HttpWebResponse response = null;
try
{
ct.ThrowIfCancellationRequested();
response = (HttpWebResponse) request.GetResponse();
}
catch (WebException)
{
if (ct.IsCancellationRequested)
{
ct.ThrowIfCancellationRequested();
}
else
{
continue;
}
}
string json;
using (response)
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
json = reader.ReadToEnd();
}
ct.ThrowIfCancellationRequested();
ArrayList objectData = JsonSerializer.Deserialize(json);
if (objectData.Count == 2)
{
if (!StringEx.IsNullOrEmpty((string) objectData[1]))
timetoken = (string) objectData[1];
ct.ThrowIfCancellationRequested();
var message = (ArrayList) objectData[0];
if (message.Count > 0)
{
channel.MessageQueue.Enqueue(new IncommingMessage(message, timetoken));
}
}
}
catch (OperationCanceledException)
{
Debug.Print(StringEx.Format("Listener for {0} channel has unsubscribed", channel.Name));
channel.Status = Status.Stopped;
return;
}
catch (Exception ex)
{
Debug.Print(StringEx.Format("Listener for {0} channel has failed ... Exception = {1}", channel.Name, ex.Message));
}
}
}
What is wrong with the following code and what should I do the resolve the issue?
Thank you very much for any help!