TCP檔案傳輸(一)

2021-06-23 00:17:46 字數 1190 閱讀 8578

最近在做網路抓包和檔案傳輸,今天遇到乙個奇怪的現象,自己查了半天也沒搞清楚,導致花了乙個下午時間就只實現了檔名和檔案長度的傳送,首先給出檔案傳輸的客戶端和伺服器端**:

一、客戶端

1)winsock com元件初始化和釋放

#include "stdafx.h"

#ifndef _winsock_startup_h_

#define _winsock_startup_h_

#include #pragma comment(lib , "ws2_32.lib")

class winsockstartup

static winsockstartup winstart;

public:

~winsockstartup()

};#endif

2)傳輸類定義

#include "stdafx.h"

#ifndef _stream_transfer_h_

#define _stream_transfer_h_

/********************************************

** transfer a .flv file use tcp

********************************************/

#include "winsockstartup.h"

struct fileinfo;

class streamtransfer;

#endif

3)傳輸**實現

#include "stdafx.h"

#include "streamtransfer.h"

#include streamtransfer::streamtransfer(string fname):filename(fname)

void streamtransfer::sendfile();

int _tmain(int argc, _tchar* argv)

;

注釋部分明顯是不對的,因為string內部的儲存資料時系統另外分配的,這回導致filename的實際資料並不是和整個結構體連續儲存的,傳送到伺服器解析出來時錯誤的。

tcp檔案傳輸

include include include include include include include include define buffer size 100 1024 1024 define file name max size 512 intmain int argc,char a...

TCP實現檔案傳輸

一直想著給之前的clouddisk專案加上乙個c s架構的檔案傳輸模組,因為之前是nginx fastcgi架構的b s架構,自己又不會前段 沒有辦法繼續增加新的功能塊。最近終於抽出時間開始寫專案了,已經選用tcp完成linux下的cs架構檔案上傳功能模組,這裡展示tcp檔案傳輸模組。socket類...

基於TCP的檔案傳輸

伺服器端處理客戶請求 public class serverthread extends thread override public void run file file new file directory.getabsolutepath file.separatorchar filename ...