我用socket这样发送一个文件行吗?
FileStream fs =
new FileStream"c:\\1.txt",FileMode.Open,System.IO.FileAccess.ReadWrite);
fs.Read(sendbyte,0,(int)fs.Length-1);
connectsock.Send(sendbyte,sendbyte.Length,0); 我用socket这样接收一个文件行吗?
int bytes=0;
string jsStr="";
byte[] jsBytes=new byte[1024];
try
{
while(true)
{
bytes = accsock.Receive(jsBytes,jsBytes.Length,0);
if(bytes<=0)
{
break;
}
jsStr+=System.Text.Encoding.ASCII.GetString(jsBytes,0,bytes);
byte[] content=System.Text.Encoding.ASCII.GetBytes(jsStr);
FileStream fs = new FileStream("d:\\1.txt",FileMode.Create,FileAccess.Read);
fs.Write(content,0,content.Length);
}
}
catch(exception ex)
{
}
FileStream fs =
new FileStream"c:\\1.txt",FileMode.Open,System.IO.FileAccess.ReadWrite);
fs.Read(sendbyte,0,(int)fs.Length-1);
connectsock.Send(sendbyte,sendbyte.Length,0); 我用socket这样接收一个文件行吗?
int bytes=0;
string jsStr="";
byte[] jsBytes=new byte[1024];
try
{
while(true)
{
bytes = accsock.Receive(jsBytes,jsBytes.Length,0);
if(bytes<=0)
{
break;
}
jsStr+=System.Text.Encoding.ASCII.GetString(jsBytes,0,bytes);
byte[] content=System.Text.Encoding.ASCII.GetBytes(jsStr);
FileStream fs = new FileStream("d:\\1.txt",FileMode.Create,FileAccess.Read);
fs.Write(content,0,content.Length);
}
}
catch(exception ex)
{
}
解决方案 »
- 求一个BAT文件的写法
- winform下如何让程序向一个网页发送请求
- 用VS给pictureBox1选择的图片保存在哪里?
- 在文本框中输入代码后,如何让dropdownlist中显示相应的项?学识不高,有代码最好!
- 高分--求asp.net源码,小型或中型网站的,仅供学习用
- datagrid如何实现向EXCEL一样,回车向右格移动,如果是最后一格则移到下一行?
- 【求助】使用button控件对字符串变量进行赋值失败
- C#如何多线程创建MDI子窗体
- C#读取Word中的checkbox。。。求大神指导
- 如何在程序中实现.net中那样风格的菜单??
- 一但超时如何删除数据库里面的数据
- 字符串转换为数字的问题
//发送
byte[] bBuffer = new byte[1024];
int nRealRead = 0;
do
{
nRealRead = fs.Read( bBuffer, 0, 1024 );
connectsock.Send(bBuffer ,nRealRead,0);
}
while( nRealRead == 1024 );//接收
byte[] bBuffer = new byte[1024];
int nRealRead = 0;
do
{
nRealRead = accsock.Receive(bBuffer ,1024,0);;
fs.Write( bBuffer, nRealRead);
}
while( nRealRead == 1024 && accsock.Available > 0 );