C# 网络编程的问题? 运行的机器上必须安装.netframework1.x,版本和你的编写环境一致,你的安装盘里边有的dotnetfx.exe。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在windows2003server系统上和windowsXP2系统上可以运行的。。要不就装个.NET framework 1.x 去下载个DotNet运行时环境吧.http://www.microsoft.com/downloads/details.aspx?FamilyID=262D25E3-F589-4842-8157-034D1E7CF3A3&displaylang=en using System;using System.Net;using System.Net.Sockets;namespace ConsoleApplication2{ class Communication { Socket soc; const int SendPoint=22221; const int bufSize=256; void Start(string Ipremode) { int byteMoved = 0; Byte [] buf = new Byte[bufSize]; Char [] charbuf = new Char[bufSize]; IPEndPoint localEP = new IPEndPoint(IPAddress.Any,SendPoint); IPEndPoint remote; soc = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); if(Ipremode=="") { soc.Bind(localEP); soc.Listen(5); while(true) { //接收客户端的连接请求 Socket readSock = soc.Accept(); remote = (IPEndPoint)readSock.RemoteEndPoint; Console.WriteLine("有客户端发来连接请求,其IP地址:{0} 端口号:{1}",remote.Address.ToString(),remote.Port); //接受客户端发过来的信息 byteMoved = readSock.Receive(buf); readSock.Shutdown(SocketShutdown.Receive);//禁止服务器接收数据 for(int i=0;i<byteMoved;i++) charbuf[i]=((char)buf[i]); Console.WriteLine("客户端发送的数据:"); Console.WriteLine(charbuf,0,byteMoved); //向客户端发送反馈信息 readSock.Send(buf,byteMoved,0); readSock.Close();//关闭通信套接字 Console.WriteLine("transfered {0} bytes",byteMoved); } soc.Close();//关闭监听套接字 } else { remote = new IPEndPoint(Dns.GetHostByName(Ipremode).AddressList[0],SendPoint); char read; Console.WriteLine("请输入要发送给服务器的信息并以“#”结束"); read=(char)Console.Read(); int i=0; while(read!='#') { buf[i++]=(Byte)read; read=(char)Console.Read(); } read='\0'; buf[i] = (Byte)read; soc.Connect(remote); byteMoved = soc.Send(buf,i,0); soc.Shutdown(SocketShutdown.Send); //接收服务器发送来的信息 byteMoved = soc.Receive(buf); for(i=0;i<byteMoved;i++) charbuf[i]=((char)buf[i]); soc.Shutdown(SocketShutdown.Receive);//禁止Socket接受数据 soc.Close(); Console.WriteLine("服务器IP地址:{0} 端口号:{1}",remote.Address.ToString(),remote.Port); Console.WriteLine("已经收到你的信息,下面是服务器反馈信息:"); Console.WriteLine(charbuf,0,byteMoved); Console.WriteLine("transfered {0} bytes",byteMoved); } } static void Main(string[] args) { Communication comm = new Communication(); if(args.Length==1) comm.Start(args[0]); else comm.Start(""); } }} 急!怎么在DataGrid时间格式yyyy-MM 程序集(Assembly)与模块的关系 C#构造函数问题 求C# 使用AT命令 控制modem 实例 vs2003打不开 如何将含图片的datagrid导出到excel表中 帮忙看这两个问题,谢谢 DataGridView根据条件查找数据行 动态域名解析问题 依赖注入 服务端的javascript 能否注册到head区 c#.net里面如何使用com接口,比如IDispatch?
http://www.microsoft.com/downloads/details.aspx?FamilyID=262D25E3-F589-4842-8157-034D1E7CF3A3&displaylang=en
using System.Net;
using System.Net.Sockets;namespace ConsoleApplication2
{
class Communication
{
Socket soc;
const int SendPoint=22221;
const int bufSize=256;
void Start(string Ipremode)
{
int byteMoved = 0;
Byte [] buf = new Byte[bufSize];
Char [] charbuf = new Char[bufSize];
IPEndPoint localEP = new IPEndPoint(IPAddress.Any,SendPoint);
IPEndPoint remote;
soc = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
if(Ipremode=="")
{ soc.Bind(localEP);
soc.Listen(5);
while(true)
{
//接收客户端的连接请求
Socket readSock = soc.Accept();
remote = (IPEndPoint)readSock.RemoteEndPoint;
Console.WriteLine("有客户端发来连接请求,其IP地址:{0} 端口号:{1}",remote.Address.ToString(),remote.Port);
//接受客户端发过来的信息
byteMoved = readSock.Receive(buf);
readSock.Shutdown(SocketShutdown.Receive);//禁止服务器接收数据
for(int i=0;i<byteMoved;i++)
charbuf[i]=((char)buf[i]);
Console.WriteLine("客户端发送的数据:");
Console.WriteLine(charbuf,0,byteMoved);
//向客户端发送反馈信息
readSock.Send(buf,byteMoved,0);
readSock.Close();//关闭通信套接字
Console.WriteLine("transfered {0} bytes",byteMoved);
}
soc.Close();//关闭监听套接字
}
else
{
remote = new IPEndPoint(Dns.GetHostByName(Ipremode).AddressList[0],SendPoint);
char read;
Console.WriteLine("请输入要发送给服务器的信息并以“#”结束");
read=(char)Console.Read();
int i=0;
while(read!='#')
{
buf[i++]=(Byte)read;
read=(char)Console.Read();
}
read='\0';
buf[i] = (Byte)read;
soc.Connect(remote);
byteMoved = soc.Send(buf,i,0);
soc.Shutdown(SocketShutdown.Send);
//接收服务器发送来的信息
byteMoved = soc.Receive(buf);
for(i=0;i<byteMoved;i++)
charbuf[i]=((char)buf[i]);
soc.Shutdown(SocketShutdown.Receive);//禁止Socket接受数据
soc.Close();
Console.WriteLine("服务器IP地址:{0} 端口号:{1}",remote.Address.ToString(),remote.Port);
Console.WriteLine("已经收到你的信息,下面是服务器反馈信息:");
Console.WriteLine(charbuf,0,byteMoved);
Console.WriteLine("transfered {0} bytes",byteMoved);
}
}
static void Main(string[] args)
{
Communication comm = new Communication();
if(args.Length==1)
comm.Start(args[0]);
else
comm.Start("");
}
}
}