Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone please post an example of MFC VC++ TCP server Programming to send data data packets.

What I have tried:

I tried many examples and could not find the solution.

The example i tried is with two objetcs from the CASyncScoket class
One for listen and one for connection

But the TCP connection is not transmitting

//Object Creation
TCPSOCKET m_Listener
TCPSOCKET m_Connected


//Listen Function
if(m_sListener.Listen()==FALSE)
{
AfxMessageBox("Unable to Listen on that port,pleasetry another port");
m_sListener.Close();
return;
}

//Bind Function
m_Listener.Bind( 172.xx.xx.xx, m_port);

//Accept function
m_Listener.Accept(m_Connected);

//Send function
m_Connected.Send (buf, sizeof(buf));

if there are changes to made , kindly please suggest an appropirate answer

Thanks in advance!!
cheers
Posted
Updated 16-Jul-19 3:30am
Comments
CPallini 16-Jul-19 13:44pm    
where is TCPSOCKET declaration (i.e. what is TCPSOCKET?) ?
Member 14499788 17-Jul-19 0:36am    
TCPSocket is a class I have declared from CAsyncSocket
# pragma once
#include "pch.h"
#include "TcpSendSocket.h"
#include "MESS_TRIALDlg.h"
#include "DataFile.h"



TcpSendSocket::TcpSendSocket()
{
//UpdateData(TRUE);


}


TcpSendSocket::~TcpSendSocket()
{
}

1 solution

Like so many people nowadays, you ignore the return values from a number of your method calls, so you have no idea if any of your code is doing what you think. Write proper code that checks all the results and examine those results to see what is happening. If things are failing then use the debugger to find out why.
 
Share this answer
 
Comments
Member 14499788 16-Jul-19 9:44am    
I already did the way you mentioned and thats why i posted here!
Also I am new in to programming.
Richard MacCutchan 16-Jul-19 10:01am    
So what results or errors do you see?
Member 14499788 16-Jul-19 10:02am    
the program is functioning I am able to receive data but not able to send data, Cannot find any errors!
Thats why I a m confused
Richard MacCutchan 16-Jul-19 10:03am    
Also, according to your comment at How to receive continous UDP data packet from the server?[^] you program works perfectly. So what have you changed since then?
Member 14499788 16-Jul-19 10:08am    
But i need to sendthe data through tCP.
In UDP i used just rec() and create () .
In TCP listen(), bind(), accept(), Send().
But i think till listen() its working .
have some problems with accept(), I think, but I amnot sure.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900