| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1049 人关注过本帖
标题:求助,关于windows socket 中文件传输的函数问题,请高手指教
只看楼主 加入收藏
luohui200866
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-3-4
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:4 
求助,关于windows socket 中文件传输的函数问题,请高手指教
请问各位高手,我在windows socket编写点对点文件传输过程中遇到两个问题:
1.传输的文件大小受限。
2.只能传输txt文件。图片和.rar都不能发送。
请高手指点,谢谢。
可以留言,也可以发我信箱,谢谢。79146069@


代码如下:// TransferSocket.cpp : implementation file
//

#include "stdafx.h"
#include "Transfer.h"
#include "TransferSocket.h"
#include "TransferDlg.h"

void CTransferSocket::OnReceive(int nErrorCode)
{
    // TODO: Add your specialized code here and/or call the base class
        CMessg msg;
        msg.Serialize(*m_aSessionIn);

        if(msg.m_iCommand==0)
        {
            m_dlg->m_RemoteShareFiles.RemoveAll();
            CListBox* list=(CListBox*)(m_dlg->GetDlgItem(IDC_REMOTE_FILE_LIST));
            list->ResetContent();
            CString temp,name;
            int i;
            temp=msg.m_strText;
            TRACE("%s\n",msg.m_strText);
            temp.TrimLeft("!");//!
            while((i=temp.Find("!"))!=-1)
            {

                name=temp.Left(i);
                TRACE("%s\n",name);
                TRACE("%s\n",temp);
                temp=temp.Mid(name.GetLength()+1);
                m_dlg->m_RemoteShareFiles.Add(name);
                list->AddString(name);
            }
            m_dlg->m_RemoteShareFiles.Add(temp);
            list->AddString(temp);
            return;
        }

        if(msg.m_iCommand==1)
        {
            CString temp,name;
            int i;
            temp=msg.m_strText;
            temp.TrimLeft("!");//!
            while((i=temp.Find("!"))!=-1)
            {
                name=temp.Left(i);
                temp=temp.Mid(name.GetLength()+1);
                m_dlg->m_NeedTransferFiles.Add(name);
            }
            m_dlg->m_NeedTransferFiles.Add(temp);
            m_dlg->SetWindowText("需要传输的文件名称处理完毕!");
            for(i=0;i<m_dlg->m_NeedTransferFiles.GetSize();i++)
            {
                CMessg m;
                TRACE("%s\n",m_dlg->m_NeedTransferFiles[i]);
                CFile file(m_dlg->m_NeedTransferFiles[i],CFile::modeRead|CFile::shareDenyWrite);
                m_dlg->SetWindowText("正在传输"+m_dlg->m_NeedTransferFiles[i]);
                byte *buffer=NULL;
                long count=file.GetLength();
                buffer= new byte[count];
                file.Read(buffer,count);
                m.m_iCommand=2;
                m.m_strText=buffer;
                m_dlg->m_TransferSocket.SendMessage(&m);
                m_dlg->SetWindowText(m_dlg->m_NeedTransferFiles[i]+"传输完毕!");
                file.Close();
            }
            m_dlg->m_NeedTransferFiles.RemoveAll();
            return;
        }

        //接收文件
        if(msg.m_iCommand==2)
        {
            int k=m_dlg->m_NeedReceiveFiles[0].ReverseFind('\\');
            CString tt;
            tt=m_dlg->m_NeedReceiveFiles[0].Mid(k+1);
            tt="E:\\"+tt;
            if(m_file.Open(tt,CFile::modeWrite|CFile::modeCreate)==FALSE)
            {
                AfxMessageBox("Failed to open the file!");
                m_file.Close();
            }
            m_file.Write(msg.m_strText,msg.m_strText.GetLength());
            m_file.Close();
            AfxMessageBox(m_dlg->m_NeedReceiveFiles[0]+"下载完毕!");
            return;
        }
搜索更多相关主题的帖子: socket windows 文件大小 点对点 图片 
2011-03-04 21:54
luohui200866
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-3-4
收藏
得分:0 
自己顶下。。。。。。。。。
2011-03-05 10:38
luohui200866
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-3-4
收藏
得分:0 
高手都忙啥了.................................,再顶
2011-03-06 20:14
红色警戒
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:19
帖 子:444
专家分:2967
注 册:2005-11-20
收藏
得分:7 
估计是在TransferSocket.h这个文件中

2011-03-06 21:53
luohui200866
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-3-4
收藏
得分:0 
回复 3楼 luohui200866
谢谢你的关注,但是我看了.h文件,里面也没有呀。
#if !defined(AFX_TRANSFERSOCKET_H__B3710126_6EF0_4A33_87F5_680BB011F089__INCLUDED_)
#define AFX_TRANSFERSOCKET_H__B3710126_6EF0_4A33_87F5_680BB011F089__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// TransferSocket.h : header file
//


#include "afxsock.h"
#include "CMessg.h"

class CTransferDlg;

/////////////////////////////////////////////////////////////////////////////
// CTransferSocket command target

class CTransferSocket : public CSocket
{
// Attributes
public:
    CArchive* m_aSessionIn;
    CArchive* m_aSessionOut;
    CSocketFile* m_sfSocketFile;
    CTransferDlg * m_dlg;
    bool m_bInit;
    bool m_bClose;
    CFile m_file;

public:
    void Init(CTransferDlg * dlg);
    BOOL SendMessage(CMessg * msg);
    void CloseSocket();

// Operations
public:
    CTransferSocket();
    virtual ~CTransferSocket();

// Overrides
public:
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CTransferSocket)
    public:
    virtual void OnReceive(int nErrorCode);
    virtual void OnClose(int nErrorCode);
    //}}AFX_VIRTUAL

    // Generated message map functions
    //{{AFX_MSG(CTransferSocket)
        // NOTE - the ClassWizard will add and remove member functions here.
    //}}AFX_MSG

// Implementation
protected:
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TRANSFERSOCKET_H__B3710126_6EF0_4A33_87F5_680BB011F089__INCLUDED_)
2011-03-07 09:51
快速回复:求助,关于windows socket 中文件传输的函数问题,请高手指教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018042 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved