Click here to Skip to main content
15,888,610 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: PlgBlt question Pin
YaronNir23-Apr-06 1:00
YaronNir23-Apr-06 1:00 
GeneralRe: PlgBlt question Pin
Stephen Hewitt23-Apr-06 1:08
Stephen Hewitt23-Apr-06 1:08 
GeneralRe: PlgBlt question Pin
YaronNir23-Apr-06 1:12
YaronNir23-Apr-06 1:12 
GeneralRe: PlgBlt question Pin
Stephen Hewitt23-Apr-06 1:20
Stephen Hewitt23-Apr-06 1:20 
GeneralRe: PlgBlt question Pin
YaronNir23-Apr-06 1:25
YaronNir23-Apr-06 1:25 
GeneralRe: PlgBlt question Pin
Stephen Hewitt23-Apr-06 1:31
Stephen Hewitt23-Apr-06 1:31 
GeneralRe: PlgBlt question Pin
YaronNir23-Apr-06 23:09
YaronNir23-Apr-06 23:09 
Questionsocket-connection oriented-winsock Pin
vanip19-Apr-06 22:50
vanip19-Apr-06 22:50 
Hi ,

I am infancy to socket programming .I need to connect to an external device through terminalserver4 and i should be able to send command & receive output. Using the following code, i am able to send data to the external device from the two send functions and able to receive data from only the first recv function.
The program is blocking at the second recv function. Please check the following code and help me if anywhere went wrong.

#define DEST_IP "10.10.1.1"
#define DEST_PORT 2001

void CSocktestDlg::process()
{
WSADATA wsaData;
if(WSAStartup(MAKEWORD(1,1),&wsaData)!=0)
{
AfxMessageBox("WSAStartup failed",MB_OK);
exit(1);
}
else
{
//AfxMessageBox("WSAStartup succeeded",MB_OK);
}

int sockfd;
struct sockaddr_in dest_addr;

//Establishing socket
sockfd=socket(AF_INET,SOCK_STREAM,0);

dest_addr.sin_family=AF_INET;
dest_addr.sin_port=htons(DEST_PORT);
dest_addr.sin_addr.s_addr=inet_addr(DEST_IP);
memset(&(dest_addr.sin_zero),'\0',8);

//For connecting
if(connect(sockfd,(struct sockaddr *)&dest_addr,sizeof(struct sockaddr))==0)
{
//AfxMessageBox("Connected to remote system successfully",MB_OK);
}
else
{
AfxMessageBox("Unable to connect to remote machine",MB_OK);
}

//For sending data
CString code= "2,76,69,68,77,73,44,73,77,68,69,73,77,68,69,0,217,105,3";
int len,bytes_sent,n,i;
CTokenEx CtlArraySpliter;
CStringArray strArray;
CtlArraySpliter.Split(code,",",strArray,TRUE);
for(i = 0; i < strArray.GetSize(); i++ )
{
//len=strArray.GetAt(i).GetLength();
n = atoi(strArray.GetAt(i));
bytes_sent=send(sockfd,(char *) &n,sizeof(int),0);
}
strArray.RemoveAll();
AfxMessageBox("Sent message through socket to remote IP",MB_OK);

Sleep(5000);

//For receiving data
char buf[50];
int p=recv(sockfd,buf,50,0);
CString s,readbuffer,soutput;
readbuffer=(CString)buf;
soutput = "";
for(i = 0;i < p;i++)
{
if (soutput == "")
{
s.Format("%d", (int)((unsigned char)readbuffer.GetAt(i)));
soutput = soutput + s;
}
else
{
s.Format("%d", (int)((unsigned char)readbuffer.GetAt(i)));
soutput = soutput + "," + s;
}
}
AfxMessageBox(soutput,MB_OK);

//second time sending......................
CtlArraySpliter.Split(code,",",strArray,TRUE);
for(i = 0; i < strArray.GetSize(); i++ )
{
//len=strArray.GetAt(i).GetLength();
n = atoi(strArray.GetAt(i));
bytes_sent=send(sockfd,(char *) &n,sizeof(int),0);
//m_myPortController.Write((char *) &n,0,0);
}
strArray.RemoveAll();
Sleep(5000);
char buf1[50];
int q=recv(sockfd,buf1,50,0);
readbuffer=(CString)buf1;

soutput = "";
for(i = 0;i < q;i++)
{
if (soutput == "")
{
s.Format("%d", (int)((unsigned char)readbuffer.GetAt(i)));
soutput = soutput + s;
}
else
{
s.Format("%d", (int)((unsigned char)readbuffer.GetAt(i)));
soutput = soutput + "," + s;
}
}
AfxMessageBox(soutput+" first port second time",MB_OK);




if (p == SOCKET_ERROR)
{
p = WSAGetLastError();
WSACleanup();
}
else
{
AfxMessageBox("Received data successfully",MB_OK);
}

//For shutting down the socket
int r=shutdown(sockfd,2);
WSACleanup();
if (r==0)
{
//AfxMessageBox("socket closed successfully",MB_OK);
}
if (r==-1)
{
AfxMessageBox("Unable to close the socket",MB_OK);
}

}

The program is blocking at the second recv() function.
Pl help me.
Thanks in advance!!
AnswerRe: socket-connection oriented-winsock Pin
includeh1019-Apr-06 23:47
includeh1019-Apr-06 23:47 
GeneralRe: socket-connection oriented-winsock Pin
vanip20-Apr-06 16:30
vanip20-Apr-06 16:30 
QuestionRecognize the programming language used to create an EXE File Pin
sdancer7519-Apr-06 22:28
sdancer7519-Apr-06 22:28 
AnswerRe: Recognize the programming language used to create an EXE File Pin
toxcct19-Apr-06 22:40
toxcct19-Apr-06 22:40 
AnswerRe: Recognize the programming language used to create an EXE File Pin
kakan20-Apr-06 0:16
professionalkakan20-Apr-06 0:16 
AnswerRe: Recognize the programming language used to create an EXE File Pin
Stephen Hewitt23-Apr-06 0:09
Stephen Hewitt23-Apr-06 0:09 
QuestionRecognize the programming language of an EXE Files Pin
sdancer7519-Apr-06 22:28
sdancer7519-Apr-06 22:28 
AnswerRe: Recognize the programming language of an EXE Files Pin
Xing Chen19-Apr-06 23:31
Xing Chen19-Apr-06 23:31 
GeneralRe: Recognize the programming language of an EXE Files Pin
toxcct19-Apr-06 23:40
toxcct19-Apr-06 23:40 
GeneralRe: Recognize the programming language of an EXE Files Pin
Xing Chen20-Apr-06 0:20
Xing Chen20-Apr-06 0:20 
AnswerRe: Recognize the programming language of an EXE Files Pin
includeh1019-Apr-06 23:34
includeh1019-Apr-06 23:34 
Questionping Pin
Paperbackwriter19-Apr-06 22:19
Paperbackwriter19-Apr-06 22:19 
AnswerRe: ping Pin
_AnsHUMAN_ 19-Apr-06 22:54
_AnsHUMAN_ 19-Apr-06 22:54 
Questionvisual studio 2005, exe file Pin
msgm6919-Apr-06 22:16
msgm6919-Apr-06 22:16 
AnswerRe: visual studio 2005, exe file Pin
YaronNir19-Apr-06 22:31
YaronNir19-Apr-06 22:31 
QuestionCompression/Decompression Wave File to MP3 and vice versa Pin
cindy_1605198819-Apr-06 21:58
cindy_1605198819-Apr-06 21:58 
AnswerRe: Compression/Decompression Wave File to MP3 and vice versa Pin
Russell'19-Apr-06 23:46
Russell'19-Apr-06 23:46 

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.