虚拟主机能不能用asp.net实现端口监听 为什么我在本地运行是正常的, 一到服务器上就不能建立监听了应该说本地客户端连接不上了,感觉就是服务器上监听没建立成功 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 怎么感觉csdn这几天人很少啊?都上班了? Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); p.StandardInput.WriteLine(" netstat -an "); p.StandardInput.WriteLine("exit"); StreamReader reader = p.StandardOutput; string strAllInfo = ""; string strLocalInfo = ""; string strLine = reader.ReadLine();也可使用socket监听端口 子夜,用socket不行吗?对于命令行我不熟那个程序在虚拟主机上不能运行吗? 这是代码public void CreatSocket() { try { int port = 5000; //string host = "192.168.164.1"; //string host = Dns.GetHostAddresses("www.ixinchen.com")[0].ToString(); string host = "122.226.56.72"; /**/ ///创建终结点(EndPoint) IPAddress ip = IPAddress.Parse(host);//把ip地址字符串转换为IPAddress类型的实例 IPEndPoint ipe = new IPEndPoint(ip, port);//用指定的端口和ip初始化IPEndPoint类的新实例 /**/ ///创建socket并开始监听 Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个socket对像,如果用udp协议,则要用SocketType.Dgram类型的套接字 s.Bind(ipe);//绑定EndPoint对像(2000端口和ip地址) s.Listen(0);//开始监听 //Console.WriteLine("等待客户端连接"); /**/ ///接受到client连接,为此连接建立新的socket,并接受信息 while (true)//定义循环,以便可以简历N次连接 { Socket temp = s.Accept();//为新建连接创建新的socket //Console.WriteLine("建立连接"); string recvStr = ""; byte[] recvBytes = new byte[1024]; int bytes; bytes = temp.Receive(recvBytes, recvBytes.Length, 0);//从客户端接受信息 recvStr += Encoding.UTF8.GetString(recvBytes, 0, bytes); //NetworkStream = new NetworkStream(ReceiveSocket); byte[] data = new byte[512]; byte[] buf = new byte[1]; buf[0] = 124; //NetworkStream.Read(data, 0, data.Length); //Msg = Encoding.UTF8.GetString(data); string Friends = Fs.getUserFriend(Convert.ToInt32(recvStr)); string[] FriendArray = Friends.Split('|'); Friend.Model fm; foreach (string D in FriendArray) { fm = new Friend.Model(); fm.UID = Convert.ToInt32(D); fm.UserName = Us.getUserName(Convert.ToInt32(D)); data = Serialize.Serializer.ObjectToByte(fm); //NetworkStream.Write(data, 0, data.Length); temp.Send(data, data.Length, 0); } //NetworkStream.Write(buf, 0, buf.Length); //ReceiveSocket.Close(); temp.Send(buf, buf.Length, 0); if (temp != null) temp.Close(); } /**/ ///给client端返回信息 //Console.WriteLine("server get message:{0}", recvStr);//把客户端传来的信息显示出来 //string sendStr = "ok!Client send message successful!"; //byte[] bs = Encoding.ASCII.GetBytes(sendStr); //temp.Send(bs, bs.Length, 0);//返回信息给客户端 //temp.Close(); //s.Close(); //Console.ReadLine(); } catch (Exception ex) { string s = ex.ToString(); } } DataList里如何获取eval绑定的值?? 一个动态生成DataTable的问题(帮我解决的我会再给你一百分) 怎样在后台生成表格和文本框 只要是asp.net程序员就进来看 如何根据数据库查询结果,自动勾选CheckBoxList的复选框呢? 有VC基础,基本了解了C#,如何能尽快的使用ASP.net,有类似学习经历的朋友进来请讲点个人经验 关于VB. NET设计的一些菜鸟问题,请哪位大虾给解释下,不甚感激~~! 下载EXCEL问题! 急,DataGrid中DropDownList的动态绑定,大家帮忙看看 ★弱弱地问一下 求助:MVC更新数据库的问题 flash实现自动循环播放
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(" netstat -an ");
p.StandardInput.WriteLine("exit");
StreamReader reader = p.StandardOutput;
string strAllInfo = "";
string strLocalInfo = "";
string strLine = reader.ReadLine();
也可使用socket监听端口
那个程序在虚拟主机上不能运行吗?
{
try
{
int port = 5000;
//string host = "192.168.164.1";
//string host = Dns.GetHostAddresses("www.ixinchen.com")[0].ToString();
string host = "122.226.56.72";
/**/
///创建终结点(EndPoint)
IPAddress ip = IPAddress.Parse(host);//把ip地址字符串转换为IPAddress类型的实例
IPEndPoint ipe = new IPEndPoint(ip, port);//用指定的端口和ip初始化IPEndPoint类的新实例 /**/ ///创建socket并开始监听
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个socket对像,如果用udp协议,则要用SocketType.Dgram类型的套接字 s.Bind(ipe);//绑定EndPoint对像(2000端口和ip地址)
s.Listen(0);//开始监听
//Console.WriteLine("等待客户端连接");
/**/ ///接受到client连接,为此连接建立新的socket,并接受信息
while (true)//定义循环,以便可以简历N次连接
{
Socket temp = s.Accept();//为新建连接创建新的socket
//Console.WriteLine("建立连接");
string recvStr = "";
byte[] recvBytes = new byte[1024];
int bytes;
bytes = temp.Receive(recvBytes, recvBytes.Length, 0);//从客户端接受信息
recvStr += Encoding.UTF8.GetString(recvBytes, 0, bytes); //NetworkStream = new NetworkStream(ReceiveSocket);
byte[] data = new byte[512];
byte[] buf = new byte[1];
buf[0] = 124;
//NetworkStream.Read(data, 0, data.Length);
//Msg = Encoding.UTF8.GetString(data); string Friends = Fs.getUserFriend(Convert.ToInt32(recvStr));
string[] FriendArray = Friends.Split('|');
Friend.Model fm;
foreach (string D in FriendArray)
{
fm = new Friend.Model();
fm.UID = Convert.ToInt32(D);
fm.UserName = Us.getUserName(Convert.ToInt32(D));
data = Serialize.Serializer.ObjectToByte(fm);
//NetworkStream.Write(data, 0, data.Length);
temp.Send(data, data.Length, 0);
}
//NetworkStream.Write(buf, 0, buf.Length);
//ReceiveSocket.Close();
temp.Send(buf, buf.Length, 0);
if (temp != null) temp.Close();
} /**/
///给client端返回信息
//Console.WriteLine("server get message:{0}", recvStr);//把客户端传来的信息显示出来
//string sendStr = "ok!Client send message successful!";
//byte[] bs = Encoding.ASCII.GetBytes(sendStr);
//temp.Send(bs, bs.Length, 0);//返回信息给客户端
//temp.Close();
//s.Close();
//Console.ReadLine();
}
catch (Exception ex)
{
string s = ex.ToString();
} }