Click here to Skip to main content
15,890,412 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC ON_WM_RBUTTONUP(), handle within control class Pin
Alexander M.,9-Jun-09 9:11
Alexander M.,9-Jun-09 9:11 
Questionalignment of modeless Pin
durban29-Jun-09 4:09
durban29-Jun-09 4:09 
AnswerRe: alignment of modeless Pin
David Crow9-Jun-09 4:18
David Crow9-Jun-09 4:18 
Questionproblem enumerating USB devices on my PDA (Windows Mobile 5.0) - project attached Pin
shpid3r9-Jun-09 3:51
shpid3r9-Jun-09 3:51 
AnswerRe: problem enumerating USB devices on my PDA (Windows Mobile 5.0) - project attached Pin
Richard Andrew x649-Jun-09 8:10
professionalRichard Andrew x649-Jun-09 8:10 
GeneralRe: problem enumerating USB devices on my PDA (Windows Mobile 5.0) - project attached Pin
shpid3r9-Jun-09 9:37
shpid3r9-Jun-09 9:37 
GeneralRe: problem enumerating USB devices on my PDA (Windows Mobile 5.0) - project attached Pin
shpid3r9-Jun-09 9:49
shpid3r9-Jun-09 9:49 
Questionquestion regarding sockets Pin
mkrtchyanmarianna9-Jun-09 2:38
mkrtchyanmarianna9-Jun-09 2:38 

<pre>
I have a question regarding sockets. I am trying to write two programs that will establish connection between each other to send and receive massages. One program sets connection the code is the following:
WSADATA WsaData;
int err = WSAStartup (0x0101, &WsaData);
s = socket(AF_INET,SOCK_STREAM,0);

fer<<"socket error code="<<WSAGetLastError()<<endl;
SOCKADDR_IN anAddr;
anAddr.sin_family = AF_INET;
if (!cm.onemach)
anAddr.sin_port = htons(tcomp->m_port);
else
anAddr.sin_port = htons(1026);
if (!cm.onemach)
anAddr.sin_addr.S_un.S_addr = inet_addr(tcomp->m_ipadr);
else
anAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
UINT TimeLimit=t;
BOOL connected;

if (connect(s, (struct sockaddr *)&anAddr, sizeof(struct sockaddr))==0)
connected=TRUE;
else
connected=FALSE;

fer<<"connecting error code="<<WSAGetLastError()<<endl;
if (!connected)
return FALSE;
{
err=send(s,sendMessage,strlen(sendMessage),0);
if (err!=0)
{
fer<<"sending error code="<<WSAGetLastError()<<endl;

}

}
And the other accepts connection:
WSADATA wsaData;
int wsaret=WSAStartup(0x0101,&wsaData);
if (wsaret == SOCKET_ERROR) AfxMessageBox("error");

while (flag)
{
servr= socket(AF_INET,SOCK_STREAM,0);
if (servr == INVALID_SOCKET)
{
flag=TRUE;
fer<<"getting message/ creating error code="<<WSAGetLastError()<<endl;
}
else
flag=FALSE;
}
anAddr.sin_family = AF_INET;
anAddr.sin_port = htons(1026);
anAddr.sin_addr.s_addr = INADDR_ANY;

err=-1;
while (err==-1)
{
err=bind( servr, (LPSOCKADDR)&anAddr, sizeof(anAddr) );
if (err!=0)
{
fer<<"binding error code="<<WSAGetLastError()<<endl;
Sleep(1000);
}
}
err=-1;
while (err!=0)
{
err = listen( servr, SOMAXCONN); //SOMAXCONN defined as 5
if (err!=0)
{
fer<<"listening error code="<<WSAGetLastError()<<endl;
Sleep(500);
}
}
SOCKADDR_IN from;
int fromlen=sizeof(from);
fer<<"before accepting error code="<<WSAGetLastError()<<endl;

//gets the address and port of remote/distant comp.
Recv=accept(servr,(struct sockaddr*)&from, &fromlen);//waits for not defined time
fer<<"accepting error code="<<WSAGetLastError()<<endl;

Last time, when I put the question I have been suggested to get WSAGetLastError(). Now I am trying this way and again the program sometimes works correct and sometimes doesn’t work and gives error 10061: Connection refused.
No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running.
Even so the second program waits on accept function the connection is not established. I will appreciate it greatly if anyone can tell me where the error comes or what can be the reason that sometimes it works and sometimes – no, can it be something with socket options or AF_INET address family. Thanks in advance.
AnswerRe: question regarding sockets Pin
CPallini9-Jun-09 2:55
mveCPallini9-Jun-09 2:55 
Questionquestion regarding sockets Pin
mkrtchyanmarianna9-Jun-09 2:15
mkrtchyanmarianna9-Jun-09 2:15 
AnswerRe: question regarding sockets Pin
led mike9-Jun-09 4:33
led mike9-Jun-09 4:33 
QuestionDetermining efficiency / most-efficient algorithm [modified] Pin
Mike the Red9-Jun-09 1:16
Mike the Red9-Jun-09 1:16 
AnswerRe: Determining efficiency / most-efficient algorithm Pin
Stuart Dootson9-Jun-09 2:11
professionalStuart Dootson9-Jun-09 2:11 
GeneralRe: Determining efficiency / most-efficient algorithm Pin
Mike the Red9-Jun-09 2:24
Mike the Red9-Jun-09 2:24 
GeneralRe: Determining efficiency / most-efficient algorithm Pin
Stuart Dootson9-Jun-09 2:29
professionalStuart Dootson9-Jun-09 2:29 
AnswerRe: Determining efficiency / most-efficient algorithm Pin
led mike9-Jun-09 4:23
led mike9-Jun-09 4:23 
AnswerRe: Determining efficiency / most-efficient algorithm Pin
Chris Losinger9-Jun-09 5:02
professionalChris Losinger9-Jun-09 5:02 
Questionquestion regarding sockets Pin
mkrtchyanmarianna9-Jun-09 1:01
mkrtchyanmarianna9-Jun-09 1:01 
QuestionRe: question regarding sockets Pin
CPallini9-Jun-09 1:50
mveCPallini9-Jun-09 1:50 
AnswerRe: question regarding sockets Pin
mkrtchyanmarianna9-Jun-09 2:14
mkrtchyanmarianna9-Jun-09 2:14 
GeneralRe: question regarding sockets Pin
CPallini9-Jun-09 2:20
mveCPallini9-Jun-09 2:20 
QuestionLoadLibraryA & LoadLibraryW Pin
chirag_chauhan8-Jun-09 23:05
chirag_chauhan8-Jun-09 23:05 
AnswerRe: LoadLibraryA & LoadLibraryW Pin
Pops80028-Jun-09 23:18
Pops80028-Jun-09 23:18 
AnswerRe: LoadLibraryA & LoadLibraryW Pin
«_Superman_»8-Jun-09 23:24
professional«_Superman_»8-Jun-09 23:24 
GeneralRe: LoadLibraryA & LoadLibraryW Pin
chirag_chauhan8-Jun-09 23:31
chirag_chauhan8-Jun-09 23:31 

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.