单编译的.exe似乎没有在我的树莓上运行。可能的原因是什么? [英] The mono-compiled .exe doesn't seem to be running on my raspberry. What might be the possible cause?
本文介绍了单编译的.exe似乎没有在我的树莓上运行。可能的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
namespace ServerSide
{
public partial class Form1 : Form
{
static TcpListener tcpListener = new TcpListener(11);
public Form1()
{
InitializeComponent();
tcpListener.Start();
//Console.WriteLine("************This is Server program************");
//Console.WriteLine("************START************");
txt_IP.Text = Dns.GetHostAddresses("localhost").ToString();
Thread newThread = new Thread(new ThreadStart(Listeners));
newThread.Start();
txt_Stream.Enabled = false;
}
/////////////////
void Listeners()
{
Socket socketForClient = tcpListener.AcceptSocket();
string ipaddress = socketForClient.RemoteEndPoint.ToString();
string ipdispaddress = socketForClient.LocalEndPoint.ToString();
//this.lbl_DisplayAddress.Text = ipaddress.ToString();
if (socketForClient.Connected)
{
//Console.WriteLine("Client:" + socketForClient.RemoteEndPoint + " now connected to server.");
NetworkStream networkStream = new NetworkStream(socketForClient);
System.IO.StreamWriter streamWriter =
new System.IO.StreamWriter(networkStream);
System.IO.StreamReader streamReader =
new System.IO.StreamReader(networkStream);
//here we recieve client's text if any.
while (true)
{
string theString = streamReader.ReadLine();
//Console.WriteLine("Message recieved by client:" + theString);
string msg = theString;
AppendTextBox(msg);
AppendIPLabel(ipaddress);
AppendDispIPLabel(ipdispaddress);
//this.txt_Stream.Text = theString.ToString();
streamWriter.WriteLine("Got it");
streamWriter.Flush();
if (theString == "exit")
break;
}
streamReader.Close();
streamWriter.Close();
networkStream.Close();
}
socketForClient.Close();
//Console.WriteLine("Press any key to exit from server program");
//Console.ReadKey();
}
public void AppendTextBox( string theString)
{
//string text = txt_Stream.Text.ToString();
//theString = text + System.Environment.NewLine + theString;
if (InvokeRequired)
{
this.Invoke(new Action<string>(AppendTextBox), new object[] { theString });
return;
}
this.lbl_BayNo.Text = theString.ToString();
}
public void AppendDispIPLabel(string ipDispaddress)
{
//string text = txt_Stream.Text.ToString();
//theString = text + System.Environment.NewLine + theString;
if (InvokeRequired)
{
this.Invoke(new Action<string>(AppendDispIPLabel), new object[] { ipDispaddress });
return;
}
this.lbl_DisplayAddress.Text = ipDispaddress.ToString();
}
public void AppendIPLabel(string ipaddress)
{
//string text = txt_Stream.Text.ToString();
//theString = text + System.Environment.NewLine + theString;
if (InvokeRequired)
{
this.Invoke(new Action<string>(AppendIPLabel), new object[] { ipaddress });
return;
}
this.lbl_ConnectedDeviceId.Text = ipaddress.ToString();
}
}
}
推荐答案
当您使用网络库时,如TcpListener
或HttpListener
代码你需要拥有权限,所以运行以下命令:
When you are using network library likeTcpListener
orHttpListener
code you need to have permissions so run the following :
sudo mono yourprogram.exe
这篇关于单编译的.exe似乎没有在我的树莓上运行。可能的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文