编译的时候你需要用/r参数将名字空间System.Net.Sockets引用进来
csc query.cs /r:System.Net.Sockets
csc query.cs /r:System.Net.Sockets
解决方案 »
- 求解ADO.NET中更新数据库的操作
- 求教 var 和=>符号怎么用
- 如何妨止程序在 Vista 下因 UAC的原因,在运行时老是弹出那个安全对话框?
- C#数据库连接写入注册表问题(VS2005 WinForm)
- X=X++为什么错?
- vs2005做的程序怎么发布呀?不用智能客户端部署
- 如何用语句在窗体中添加按扭!!
- 哪位大哥能给我讲一下装配件的概念,不要太抽象了,谢谢。
- 请问如何得知TreeView的Click事件发生在具体的哪个Node上
- 请教: 关于Windows Services 的安装问题!!!(Thank you!)
- 水晶报表-关于分组显示的问题·急
- 求教用socket连接商用web服务器的问题?急 急 急!
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
版权所有 (C) Microsoft Corporation 2001。保留所有权利。error CS0006: 未能找到元数据文件“System.Net.Sockets”还有,怎么样将服务器的返回信息显示出来?谢谢了~~
using System;
using System.Net.Sockets;
using System.Text;
public class query
{
static void Main(String[] args)
{
String queryinfo="get http/1.0\r\n";
TcpClient client=new TcpClient(args[0],80);
NetworkStream ns=client.GetStream();
byte[] sendquery=Encoding.ASCII.GetBytes(queryinfo);
ns.Write(sendquery,0,sendquery.Length);
byte[] buffer=new byte[1024];
int result=ns.Read(buffer,0,buffer.Length);
Console.WriteLine(Encoding.ASCII.GetString(buffer,0,result));
Console.ReadLine();
}
} 依然不对,郁闷……
知道的说一下~~
谢谢了
上面这个例子是正常的,但我在你这个代码中发现了很多导致问题的控制符0xa3 0xa0,你使用什么东西写的,建议你重要写一份
但是出现异常的时候,有点不爽,会弹出窗口,这样如何解决?谢谢
using System;
using System.Text;
using System.Net.Sockets;
using System.Net;
public class query
{
static void Main(string[] args)
{
IPEndPoint point;
Socket socket;
string sendstr;
if(args.Length==0)Console.WriteLine("Usage:queryweb Ip Port.");
else if(args.Length==1)Console.WriteLine("not enough args.");
else if(args.Length==2)
{
IPAddress host=IPAddress.Parse(args[0]);
int port=Int32.Parse(args[1]);
point=new IPEndPoint(host,port);
socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
Console.WriteLine("尝试连接主机"+host+"的"+port+"端口……");
try
{
socket.Connect(point);
}
catch(Exception e)
{
Console.WriteLine("无法连接主机"+host+"的"+port+"端口……");
}
sendstr="GET /http/1.0\r\n";
byte[] bytessendstr=new byte[1024];
bytessendstr=Encoding.ASCII.GetBytes(sendstr);
try
{
socket.Send(bytessendstr,bytessendstr.Length,0);
}
catch(Exception)
{
Console.WriteLine("发送查询信息失败……");
}
string recvstr="";
byte[] recvbytes=new byte[1024];
int bytes=0;
while(true)
{
bytes=socket.Receive(recvbytes,recvbytes.Length,0);
if(bytes<=0)
break;
recvstr+=Encoding.ASCII.GetString(recvbytes,0,bytes);
}
Console.WriteLine(recvstr);
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
}
}