使用C#进行点对点通讯和文件传输(2)
俺这里只给出一部分代码,其余的您自己可以发挥以下:
public class executefile
{
private string host ;
private int port ;
private string filename ;
private string cmdparam ;
public executefile(string strhost,int iport,string strfilename,string strcmdparam)
{
host = strhost ;
port = iport ;
filename = strfilename ;
cmdparam = strcmdparam ;
}
public void send()
{
socket s = null ;
try
{
s = communclass.connecttoserver(host,port) ;
communclass.writecommandtosocket(s,"executefile") ;
communclass.writecommanddesctosocket(s,filename) ;
communclass.writedynamictexttosocket(s,"",null) ;
messagebox.show(communclass.readdynamictextfromsocket(s)) ;
}
catch (exception e)
{
messagebox.show(e.message) ;
}
finally
{
if (s != null)
s.close() ;
}
}
}
下面是服务器端接受信息的代码:
创建监听:
/// <summary>
/// 再给定的主机和端口上创建监听程序
/// </summary>
/// <param name="straddress"></param>
/// <param name="iport"></param>
private void buildingserver(string straddress,int iport)
{
ipaddress ipaddress = dns.resolve(straddress).addresslist[0];
try
{
listener = new tcplistener(ipaddress, iport);
}
catch ( exception e)
{
addi
Tag: 点对点通讯 ,文件传输
文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。