Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

socket programming..

Status
Not open for further replies.

DGoulston

Technical User
Jun 17, 2002
21
GB
ok i have a program that is running gettin network/user data and i am adding a bit to it so it is a winsock server, i then have another program that is the client. basicall im just trying to get them to comunicate at the mo. here is the code:
Code:
//SERVER:
BOOL Create_Socket()
{
   CString dwValue = "Server";
   CAsyncSocket *sockSrvr;
   int nPort = 25;
   sockSrvr->Create(nPort,SOCK_DGRAM);
   sockSrvr->Bind(nPort);
   sockSrvr->Listen();
   // construct a new, empty socket 
   CAsyncSocket sockRecv;
   // accept connection
   sockSrvr->Accept(sockRecv))
   TCHAR buff[4096];
   int nRead;
   nRead = sockSrvr->Receive(buff, 4096); 
   CString CSbuff;
   CSbuff = buff;
   if (sockSrvr->Send(CSbuff,CSbuff.GetLength()))
   {
 		return TRUE;
   }
	
   return TRUE;
}

Code:
//Client:

CString change_code(CString rep_str)
{
	CString dwValue = "Client";
	CString strAddr;
	int nPort = 25;
	strAddr = "10.0.11.29";
	CSocket sockClient;
	sockClient.Create();
	// seek a connection 
	sockClient.Connect((LPCTSTR)strAddr, nPort);
	TCHAR buff[4096];
	int nRead;
	if (sockClient.Send(dwValue,dwValue.GetLength()))
	{
		nRead = sockClient.Receive(buff, 4096); 
	}
	return dwValue;
}

so all im tryin to do is send data down, have it send it back..

any help???

regards
Dal

####################
# #
# Darren@DGoulston.com #
###################
 
first of all try to use another port, for example 6000, ebcause 25 could be used by some services

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 

Dal, you are listening on a UDP socket. UDP is connectionless.

I'm a hardcore sockets programmer as I work for a VoIP company and create 700 virtual phones on one PC to exercise the system. I have developed an MFC dialog application that allows me to create UDP or TCP sockets, connect, listen, send, receive, etc. I use it for development purposes. Could be a very good learning tool for you. Start two instances of it on the same pc (or different PCs) and you can send data back and forth, tcp or udp. You can check out my sockets class and use it as is or customize it to suit your needs. You can set debug to use trace msgs, message boxes, or pass in a pointer to a CWnd to print messages to any class derived from CWnd (CRichEdit, etc). To send data it's as easy as this:

CSockClass Sock;
Sock.SetDebugLevel(DEBUG_INFO,DEBUG_CONSOLE, this);
Sock.StartUp();
Sock.OpenSock(iSocketType);
Sock.NonBlocking(bNonBlocking);
Sock.UDPSendTo(cData,cDestAddress,m_iDestPort);

If interested give me your email and I'll send it to you.

Cheers,

Brother C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top