求助,关于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;
}