私のアプリケーションはユーザーの資格情報をサーバーに送信します。正しい場合、サーバーはクライアントに資格情報が間違っているか正しいかを伝えるパケットを送信します。いくつかのダミー テストの後、このコード行が原因でクライアントがクラッシュしました。
var count = await reader.LoadAsync(512);
デバッグすると、カウントが 0 であることが示されます。
しかし、クラッシュする前に、7 つのダミー リクエストをサーバーに送信することができました。クライアントは 7 件の返信を読むことができました。
private async void loginButtonEvent(object sender, RoutedEventArgs e)
{
//disable the button so the user can't spam the login button and flood packets
loginButton.IsEnabled = false;
//if the user is connected to the server, then allow
if(connected)
{
//get the stream
DataWriter writer = new DataWriter(clientSocket.OutputStream);
//custom class (like a packet IO, messafe frame/ framing
MessageData md = new MessageData();
md.MyUser = new User(usernameTextBox.Text, passwordTextBox.Text);
md.MyType = MessageData.mType.LOGINREQUEST;
//Serialize it into a string, thank you newton.Json
string output = JsonConvert.SerializeObject(md);
//write to the server
writer.WriteString(output);
//dedicate and push
await writer.StoreAsync();
//flush like you flush a toilet so it doesn't get clogged in the pipeline
await writer.FlushAsync();
//detatch the stream, not sure why?
writer.DetachStream();
//get the input stream
DataReader reader = new DataReader(clientSocket.InputStream);
//create string to hold the data
string receivedData;
//dynamically process the data
reader.InputStreamOptions = InputStreamOptions.Partial;
//store the bytes in count? why do we pass 512? What if I send a picture to the server and it is 1mb?
var count = await reader.LoadAsync(512);
//covert the byte to a string
receivedData = reader.ReadString(count);
//construct the md object into what the server sent
md = JsonConvert.DeserializeObject<MessageData>(receivedData);
switch (md.MyType)
{
case MessageData.mType.LOGINFAILED:
messageBox("Username or Password is wrong");
//Todo://
break;
case MessageData.mType.LOGINSUCCESS:
messageBox("Logged");
//TODO: Go to login screen
break;
}
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(1));
}
loginButton.IsEnabled = true;
}
これをもう一度テストしたところ、今度は 12 個のパケットをサーバーに送信でき、クライアントが解釈できる 12 個のパケットを受信できました。
繰り返しますが、エラーは次の場所にあります
var count = await reader.LoadAsync(512);
タイプ 'System.ObjectDisposedException' の例外が MobileApp.exe で発生しましたが、ユーザー コードで処理されませんでした
Object Disposable Exception は、ユーザー コードによって処理されませんでした。