C# project里 代码都没有F5的时候 就会出错误 怎么解决 代码如下 20
StringxMode="A";if(radioButton7.Checked){xMode="A";}//Autoif(radioButton3.Checked){xM...
String xMode = "A";
if (radioButton7.Checked) { xMode = "A"; } //Auto
if (radioButton3.Checked) { xMode = "I"; } //Roll left
if (radioButton4.Checked) { xMode = "J"; } //Roll right
if (radioButton5.Checked) { xMode = "B"; } //Flash
if (radioButton6.Checked) { xMode = "C"; } //Hold
String xSpeed = "1"; String xPause = "3";
String A1 = "\u0000\u0000\u0000\u0000\u0000\u0001FF00";
string B2 = "\u0002" + "A" + "0" + xMode + xSpeed + xPause + "7F";
string G7 = "01001200";
string G7a = "000" + "1";
string H8 = textBox2.Text + "\u0003" + "0564" + "\u0004";
string Display = A1 + B2 + G7 + G7a + H8;
try
{
networkStream = socketForServer.GetStream();
}
catch (SystemException se)
{
MessageBox.Show(se.ToString());
}
byte[] outStream = System.Text.Encoding.ASCII.GetBytes(Display);
networkStream.Write(outStream, 0, outStream.Length);
networkStream.Flush();
byte[] inStream = new byte[10025];
networkStream.Read(inStream, 0, (int)socketForServer.ReceiveBufferSize);
string returndata = System.Text.Encoding.ASCII.GetString(inStream);
textBox3.Text = textBox3.Text + Environment.NewLine + " >> " + "Data from Server : " + returndata;
} 展开
if (radioButton7.Checked) { xMode = "A"; } //Auto
if (radioButton3.Checked) { xMode = "I"; } //Roll left
if (radioButton4.Checked) { xMode = "J"; } //Roll right
if (radioButton5.Checked) { xMode = "B"; } //Flash
if (radioButton6.Checked) { xMode = "C"; } //Hold
String xSpeed = "1"; String xPause = "3";
String A1 = "\u0000\u0000\u0000\u0000\u0000\u0001FF00";
string B2 = "\u0002" + "A" + "0" + xMode + xSpeed + xPause + "7F";
string G7 = "01001200";
string G7a = "000" + "1";
string H8 = textBox2.Text + "\u0003" + "0564" + "\u0004";
string Display = A1 + B2 + G7 + G7a + H8;
try
{
networkStream = socketForServer.GetStream();
}
catch (SystemException se)
{
MessageBox.Show(se.ToString());
}
byte[] outStream = System.Text.Encoding.ASCII.GetBytes(Display);
networkStream.Write(outStream, 0, outStream.Length);
networkStream.Flush();
byte[] inStream = new byte[10025];
networkStream.Read(inStream, 0, (int)socketForServer.ReceiveBufferSize);
string returndata = System.Text.Encoding.ASCII.GetString(inStream);
textBox3.Text = textBox3.Text + Environment.NewLine + " >> " + "Data from Server : " + returndata;
} 展开
3个回答
展开全部
这段代码如果 Socket 不存在问题,那么极可能存在问题的代码是:
byte[] inStream = new byte[10025];
networkStream.Read(inStream, 0, (int)socketForServer.ReceiveBufferSize);
你能确保 ReceiveBufferSize 小于或等于 10025 字节码(ReceiveBufferSize 默认 8192 字节),建议更改为:
byte[] inStream = new byte[10025];
int len = networkStream.Read(inStream, 0, inStream.Length);
// 通过返回值 len 判断是否已经读取完毕(返回零意味读取完毕,否则非零)。
以下代码更加简洁,提供参考:
// 向网络流写入字符串数据
System.IO.StreamWriter writer = new System.IO.StreamWriter(networkStream, System.Text.Encoding.ASCII);
writer.Write(Display);
// 从网络流中读取字符串数据
System.IO.StreamReader reader = new System.IO.StreamReader(networkStream, System.Text.Encoding.ASCII);
string returndata = reader.ReadToEnd();
byte[] inStream = new byte[10025];
networkStream.Read(inStream, 0, (int)socketForServer.ReceiveBufferSize);
你能确保 ReceiveBufferSize 小于或等于 10025 字节码(ReceiveBufferSize 默认 8192 字节),建议更改为:
byte[] inStream = new byte[10025];
int len = networkStream.Read(inStream, 0, inStream.Length);
// 通过返回值 len 判断是否已经读取完毕(返回零意味读取完毕,否则非零)。
以下代码更加简洁,提供参考:
// 向网络流写入字符串数据
System.IO.StreamWriter writer = new System.IO.StreamWriter(networkStream, System.Text.Encoding.ASCII);
writer.Write(Display);
// 从网络流中读取字符串数据
System.IO.StreamReader reader = new System.IO.StreamReader(networkStream, System.Text.Encoding.ASCII);
string returndata = reader.ReadToEnd();
展开全部
发错误提示
追问
byte[] outStream = System.Text.Encoding.ASCII.GetBytes(Display);
networkStream.Write(outStream, 0, outStream.Length);
networkStream.Flush();
byte[] inStream = new byte[10025];
networkStream.Read(inStream, 0, (int)socketForServer.ReceiveBufferSize);
string returndata = System.Text.Encoding.ASCII.GetString(inStream);
提示错在这边
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
提示的错误是什么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询