Click here to Skip to main content
15,892,199 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralJavascript/DHTML and MFC Pin
Condorito7-Mar-02 4:52
Condorito7-Mar-02 4:52 
GeneralRe: Javascript/DHTML and MFC Pin
Joaquín M López Muñoz7-Mar-02 6:02
Joaquín M López Muñoz7-Mar-02 6:02 
GeneralRe: Javascript/DHTML and MFC Pin
Shog97-Mar-02 10:40
sitebuilderShog97-Mar-02 10:40 
GeneralCStringArray error catching Pin
RK_20007-Mar-02 4:29
RK_20007-Mar-02 4:29 
GeneralRe: CStringArray error catching Pin
Tomasz Sowinski7-Mar-02 4:53
Tomasz Sowinski7-Mar-02 4:53 
GeneralRe: CStringArray error catching Pin
RK_20007-Mar-02 5:31
RK_20007-Mar-02 5:31 
GeneralRe: CStringArray error catching Pin
Joaquín M López Muñoz7-Mar-02 5:41
Joaquín M López Muñoz7-Mar-02 5:41 
GeneralCSocket problem Pin
Vladimir Georgiev7-Mar-02 4:23
Vladimir Georgiev7-Mar-02 4:23 
Hi, the those are my client and server procedures using CSocket to send a file... When I run the programs onto a single machine, I receive the file without any problems...
But when I run them on two different computers, I get a different file... something is changing my buffer that I send via the socket. Can anyone help me? Does anyone know an article explaining how to use CSocketFile and an example source???

RECEIVING PROCEDURE:
UINT SendProcThread(LPVOID pParam)
{
size = 128;
CSocket sock;
sock.Create(12234);
sock.Listen();

CSocket recv;
sock.Accept(recv);

char num[20];
recv.Receive(num, 20, NULL);
length = atoi(num);
TRACE ("\n%d - length\n", length);

recv.Receive(num, 20, NULL);
int f_name_len = atoi(num);
TRACE("\n%d - name len\n", f_name_len);

char* name;
name = (char*) malloc(f_name_len);
recv.Receive(name, f_name_len, NULL);
strName = name;

strName.ReleaseBuffer(f_name_len);
TRACE("\n%s - name\n", strName);

int l = length/size;
char* buf;
buf = (char*) malloc(size);

try {
CFile file;
file.Open(strName, CFile::modeCreate | CFile::modeReadWrite, NULL);
for (int i=0; i<l; i++)="" {
="" recv.receive(buf,="" size,="" 0);
="" file.seek(size*i,="" cfile::begin);
="" file.write(buf,="" size);
="" }
="" length%size);
="" file.seek(size*l,="" file.close();
="" catch="" (cfileexception*="" e)="" e-="">ReportError();
e->Delete();
}

recv.Close();
sock.Close();

free(name);
free(buf);

CString msg;
msg.Format("%s file with legth %d has arrived!", strName, length);
AfxMessageBox(msg);

return 0;
}

SENDING PROC:
UINT SendFileThreadProc(LPVOID pParam)
{
size = 128;

char* buf;
buf = (char*) malloc(size);

CSocket socket;

socket.Create();
socket.Connect(m_dest_name, 12234);

char num[20];
itoa(length, num, 10);
socket.Send(num, 20, NULL);
TRACE ("\n%d - length\n", atoi(num));

itoa(m_strName.GetLength(), num, 10);
socket.Send(num, 20, NULL);
TRACE("\n%d - name len\n", atoi(num));

socket.Send(m_strName, m_strName.GetLength(), NULL);
TRACE("\n%s - name\n", m_strName);

int l = length/size;

try {
CFile file;
file.Open(m_strFileName, CFile::modeRead, NULL);
for (int i=0; i<l; i++)="" {
="" file.seek(i*size,="" cfile::begin);
="" file.read(buf,="" size);
="" socket.send(buf,="" size,="" 0);
="" }
="" file.seek(size*l,="" length%size);
="" length%size,="" file.close();
="" catch="" (cfileexception*="" e)="" e-="">ReportError();
e->Delete();
}


socket.Close();
free(buf);

return 0;
}

"Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
GeneralRe: CSocket problem Pin
Joaquín M López Muñoz7-Mar-02 5:57
Joaquín M López Muñoz7-Mar-02 5:57 
GeneralHELP Pin
sardinka7-Mar-02 3:15
sardinka7-Mar-02 3:15 
GeneralRe: HELP Pin
Carlos Antollini7-Mar-02 3:17
Carlos Antollini7-Mar-02 3:17 
GeneralVC++:CAsyncSocket and SDI Pin
crasher7-Mar-02 3:09
crasher7-Mar-02 3:09 
GeneralRe: VC++:CAsyncSocket and SDI Pin
RobJones7-Mar-02 4:11
RobJones7-Mar-02 4:11 
GeneralRe: VC++:CAsyncSocket and SDI Pin
fara7-Mar-02 13:59
fara7-Mar-02 13:59 
GeneralRe: VC++:CAsyncSocket and SDI Pin
lucy7-Mar-02 4:13
lucy7-Mar-02 4:13 
QuestionHow to deal with a Word document? Pin
big20027-Mar-02 3:05
big20027-Mar-02 3:05 
AnswerRe: How to deal with a Word document? Pin
Carlos Antollini7-Mar-02 3:22
Carlos Antollini7-Mar-02 3:22 
Generalpacking bytes to form an int (32bit) Pin
Merle Pittman7-Mar-02 2:36
Merle Pittman7-Mar-02 2:36 
GeneralRe: packing bytes to form an int (32bit) Pin
Jon Hulatt7-Mar-02 2:51
Jon Hulatt7-Mar-02 2:51 
GeneralRe: packing bytes to form an int (32bit) Pin
Tomasz Sowinski7-Mar-02 2:50
Tomasz Sowinski7-Mar-02 2:50 
Generaldrive list, drive type and drive name Pin
Guy Lecomte7-Mar-02 2:27
Guy Lecomte7-Mar-02 2:27 
GeneralRe: drive list, drive type and drive name Pin
Tomasz Sowinski7-Mar-02 2:28
Tomasz Sowinski7-Mar-02 2:28 
GeneralRe: drive list, drive type and drive name Pin
Atul Dharne7-Mar-02 2:48
Atul Dharne7-Mar-02 2:48 
GeneralParsing MS Word file Pin
7-Mar-02 2:21
suss7-Mar-02 2:21 
GeneralRe: Parsing MS Word file Pin
Michael P Butler7-Mar-02 2:39
Michael P Butler7-Mar-02 2:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.