socket文件下载|在win7下用socket下载文件报错

1. 在win7下用socket下载文件报错

Windows Vista 以及来以上的版本,源在安全机制上新增了许多特性,这些特性微软都为程序开发人员提供了详细的文档,都在 MSDN 里面,一般设计 Windows Vista 或者 Win7 应用程序,如果程序需要进行某些高级的行为都需要经过下面步骤:a . 获取最高管理员权限(有对应的 API 可以实现)b . 进行操作c . 放弃管理员权限或者简单一点,你告诉用户,以管理员权限来运行你的应用程序,这样防火墙什么的都会放行的了。

2. c语言socket.h头文件来源地址

如果在Windows下面编程,试一试#include <winsock.h> 或者#include <winsock2.h>UNIX/linux下面是socket.h,不同平台头文件不一样的,但是内容大同小异。

3. 在文件下载时报错“socket write error”怎么办

1、这个是应为用户创建的是长连接,之后突然关闭了本地的handler,导致流读取错误,所以版就报错了。

2、这个如果是用来转发的,权之后发现本地停止后报出来的,是不影响正常使用的,之后重新运行代码,会再次进行连接的,建议这个本地的socket不要随意的断开连接,否则如果有流没读完,可能会导致后续程序出问题的。

3、文件能成功下载struts代码:

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { // TODO Auto-generated method stub String path = request.getParameter("path").replace("\\", "\")。

4. 怎么用C语言 socket 实现 下载网页链接文件!!!

网页上的链接,一般都是http下载,比如你右键一个链接,然后另存为这种。http是在tcp之上的协议,你要自己用socket实现,既费时费力,也没有必要,可以去搜一些开源的http协议开发的库,可以找到很多。同样的,如果是ftp下载的话,也可以直接找支持的开源库,进行开发。总之要先明确一点,你的下载时通过何种协议进行的,再找对应的开源库就OK了。

5. Socket编程。以下载文件为例,用伪代码描述MFC的工作线程的执行流程

HTTP GET/POSTconnectsend "GET /abc.rar HTTP/1.1\r\n\r\n"recv

6. socket传送文件

点对点传输文件/*import java.io.*;import java.net.*;import java.util.*;*/private HttpURLConnection connection;//存储连接 private int downsize = -1;//下载文件大小,初始值为-1 private int downed = 0;//文加已下载大小,初始值为0 private RandomAccessFile savefile;//记录下载信息存储文件 private URL fileurl;//记录要下载文件的地址 private DataInputStream fileStream;//记录下载的数据流try{ /*开始创建下载的存储文件,并初始化值*/ File tempfileobject = new File("h:\\webwork-2.1.7.zip"); if(!tempfileobject.exists()){ /*文件不存在则建立*/ tempfileobject.createNewFile(); } savefile = new RandomAccessFile(tempfileobject,"rw"); /*建立连接*/ fileurl = new URL("https://webwork.dev.java.net/files/documents/693/9723/webwork-2.1.7.zip"); connection = (HttpURLConnection)fileurl.openConnection(); connection.setRequestProperty("Range","byte="+this.downed+"-"); this.downsize = connection.getContentLength(); //System.out.println(connection.getContentLength()); new Thread(this).start(); } catch(Exception e){ System.out.println(e.toString()); System.out.println("构建器错误"); System.exit(0); } public void run(){ /*开始下载文件,以下测试非断点续传,下载的文件存在问题*/ try{ System.out.println("begin!"); Date begintime = new Date(); begintime.setTime(new Date().getTime()); byte[] filebyte; int onecelen; //System.out.println(this.connection.getInputStream().getClass().getName()); this.fileStream = new DataInputStream( new BufferedInputStream( this.connection.getInputStream())); System.out.println("size = " + this.downsize); while(this.downsize != this.downed){ if(this.downsize – this.downed > 262144){//设置为最大256KB的缓存 filebyte = new byte[262144]; onecelen = 262144; } else{ filebyte = new byte[this.downsize – this.downed]; onecelen = this.downsize – this.downed; } onecelen = this.fileStream.read(filebyte,0,onecelen); this.savefile.write(filebyte,0,onecelen); this.downed += onecelen; System.out.println(this.downed); } this.savefile.close(); System.out.println("end!"); System.out.println(begintime.getTime()); System.out.println(new Date().getTime()); System.out.println(begintime.getTime() – new Date().getTime()); } catch(Exception e){ System.out.println(e.toString()); System.out.println("run()方法有问题!"); }}/***//FileClient.javaimport java.io.*;import java.net.*;public class FileClient {public static void main(String[] args) throws Exception {//使用本地文件系统接受网络数据并存为新文件File file = new File("d:\\fmd.doc");file.createNewFile();RandomAccessFile raf = new RandomAccessFile(file, "rw");// 通过Socket连接文件服务器Socket server = new Socket(InetAddress.getLocalHost(), 3318);//创建网络接受流接受服务器文件数据InputStream netIn = server.getInputStream();InputStream in = new DataInputStream(new BufferedInputStream(netIn));//创建缓冲区缓冲网络数据byte[] buf = new byte[2048];int num = in.read(buf);while (num != (-1)) {//是否读完所有数据raf.write(buf, 0, num);//将数据写往文件raf.skipBytes(num);//顺序写文件字节num = in.read(buf);//继续从网络中读取文件}in.close();raf.close();}}//FileServer.javaimport java.io.*;import java.util.*;import java.net.*;public class FileServer {public static void main(String[] args) throws Exception {//创建文件流用来读取文件中的数据File file = new File("d:\\系统特点.doc");FileInputStream fos = new FileInputStream(file);//创建网络服务器接受客户请求ServerSocket ss = new ServerSocket(8801);Socket client = ss.accept();//创建网络输出流并提供数据包装器OutputStream netOut = client.getOutputStream();OutputStream doc = new DataOutputStream(new BufferedOutputStream(netOut));//创建文件读取缓冲区byte[] buf = new byte[2048];int num = fos.read(buf);while (num != (-1)) {//是否读完文件doc.write(buf, 0, num);//把文件数据写出网络缓冲区doc.flush();//刷新缓冲区把数据写往客户端num = fos.read(buf);//继续从文件中读取数据}fos.close();doc.close();}}*/

7. 怎样利用socket发送.exe 文件实现下载功能

想在公司里偷偷地传文件还是公开地传文件,两者的目的不同,技术解决方案也不一样。

8. C# Winform 多线程 SOCKET 文件上传,下载

这可是很麻烦的,自己到网上找吧

9. 怎样用socket实现点对点的文件传输

在两台计算机传输文件之前,必需得先有一台计算机建立套接字连接并绑定一个固定得端口,并在这个端口侦听另外一台计算机的连接请求。socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);socket.Blocking = true ;IPEndPoint computernode1 = new IPEndPoint(serverIpadress, 8080);socket.Bind(computernode1);socket.Listen(-1);当有其他的计算机发出连接请求的时候,被请求的计算机将对每一个连接请求分配一个线程,用于处理文件传输和其他服务。while ( true ){clientsock = socket.Accept();if ( clientsock.Connected ){Thread tc = new Thread(new ThreadStart(listenclient));tc.Start();}}下面的代码展示了listenclient方法是如何处理另外一台计算机发送过来的请求。首先并对发送过来的请求字符串作出判断,看看是何种请求,然后决定相应的处理方法。void listenclient(){Socket sock = clientsock ;try{while ( sock != null ) {byte[] recs = new byte[32767];int rcount = sock.Receive(recs,recs.Length,0) ;string message = System.Text.Encoding.ASCII.GetString(recs) ;//对message作出处理,解析处请求字符和参数存储在cmdList 中execmd=cmdList[0];sender = null ;sender = new Byte[32767];string parm1 = "";//目录列举 if ( execmd == "LISTING" ) {ListFiles(message);continue ;} //文件传输if ( execmd == "GETOK" ){cmd = "BEGINSEND " + filepath + " " + filesize ;sender = new Byte[1024];sender = Encoding.ASCII.GetBytes(cmd);sock.Send(sender, sender.Length , 0 );//转到文件下载处理DownloadingFile(sock);continue ;} }}catch(Exception Se){string s = Se.Message;Console.WriteLine(s);}}至此,基本的工作已经完成了,下面我们看看如何处理文件传输的。while(rdby < total && nfs.CanWrite){//从要传输的文件读取指定长度的数据len =fin.Read(buffed,0,buffed.Length) ;//将读取的数据发送到对应的计算机nfs.Write(buffed, 0,len);//增加已经发送的长度rdby=rdby+len ; } 从上面的代码可以看出是完成文件转换成FileStream 流,然后通过NetworkStream绑定对应的套节子,最后调用他的write方法发送到对应的计算机。我们再看看接受端是如何接受传输过来的流,并且转换成文件的:NetworkStream nfs = new NetworkStream(sock) ;try{//一直循环直到指定的文件长度while(rby < size){byte[] buffer = new byte[1024] ;//读取发送过来的文件流int i = nfs.Read(buffer,0,buffer.Length) ;fout.Write(buffer,0,(int)i) ;rby=rby+i ;} fout.Close() ; 从上面可以看出接受与发送恰好是互为相反的过程,非常简单。至此,单方向的文件传输就完成了,只需要在每个对等的节点上同时实现上面的发送和接受的处理代码就可以做到互相传输文件了。

10. sys/socket.h等头文件为何在visual studio 2013中没有哪里可以下载或者解决

sys/socket.h是linux下专用的,你要是想写的代码在vs2013中能编译就用windows下的API函数,多学点跨平台的代码,我也在学习中…


赞 (0)