Handle server error's
This commit is contained in:
@@ -27,23 +27,36 @@ namespace MusicPlayer
|
|||||||
Console.WriteLine(encodedstring);
|
Console.WriteLine(encodedstring);
|
||||||
HttpWebRequest server = (HttpWebRequest)WebRequest.Create(ip+":"+port+"/"+encodedstring);
|
HttpWebRequest server = (HttpWebRequest)WebRequest.Create(ip+":"+port+"/"+encodedstring);
|
||||||
server.KeepAlive = false;
|
server.KeepAlive = false;
|
||||||
HttpWebResponse respond = (HttpWebResponse)server.GetResponse();
|
try {
|
||||||
Stream streamResponse = respond.GetResponseStream();
|
HttpWebResponse respond = (HttpWebResponse)server.GetResponse();
|
||||||
StreamReader streamRead = new StreamReader(streamResponse);
|
Stream streamResponse = respond.GetResponseStream();
|
||||||
Char[] readBuff = new Char[256];
|
StreamReader streamRead = new StreamReader(streamResponse);
|
||||||
int count = streamRead.Read(readBuff, 0, 256);
|
Char[] readBuff = new Char[256];
|
||||||
string data = "";
|
int count = streamRead.Read(readBuff, 0, 256);
|
||||||
while (count > 0)
|
string data = "";
|
||||||
{
|
while (count > 0)
|
||||||
String outputData = new String(readBuff, 0, count);
|
{
|
||||||
data +=outputData;
|
String outputData = new String(readBuff, 0, count);
|
||||||
count = streamRead.Read(readBuff, 0, 256);
|
data += outputData;
|
||||||
|
count = streamRead.Read(readBuff, 0, 256);
|
||||||
|
}
|
||||||
|
JObject o = JObject.Parse(data);
|
||||||
|
respond.Close();
|
||||||
|
streamResponse.Close();
|
||||||
|
streamRead.Close();
|
||||||
|
return o;
|
||||||
}
|
}
|
||||||
JObject o = JObject.Parse(data);
|
catch(WebException e)
|
||||||
respond.Close();
|
{
|
||||||
streamResponse.Close();
|
Console.WriteLine("Server is offline");
|
||||||
streamRead.Close();
|
}
|
||||||
return o;
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Er is iets fout gegaan bij het communiceren met de server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemoryStream downloadArtwork(string album)
|
public MemoryStream downloadArtwork(string album)
|
||||||
|
|||||||
Reference in New Issue
Block a user