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

C / C++ / MFC

 
GeneralRe: Problems with accessing a control from another class Pin
James P8-Apr-02 5:31
James P8-Apr-02 5:31 
GeneralRe: Problems with accessing a control from another class Pin
Mazdak8-Apr-02 6:02
Mazdak8-Apr-02 6:02 
Generallisten() problem Pin
lucy8-Apr-02 3:21
lucy8-Apr-02 3:21 
GeneralRe: listen() problem Pin
Bob Groves8-Apr-02 9:15
Bob Groves8-Apr-02 9:15 
GeneralRe: listen() problem Pin
lucy9-Apr-02 4:05
lucy9-Apr-02 4:05 
GeneralRe: listen() problem Pin
Bob Groves9-Apr-02 4:08
Bob Groves9-Apr-02 4:08 
GeneralRe: listen() problem Pin
lucy9-Apr-02 5:20
lucy9-Apr-02 5:20 
GeneralRe: listen() problem Pin
Bob Groves9-Apr-02 6:01
Bob Groves9-Apr-02 6:01 
I've never used the FD_??? macros, but I just tried the following in the 10 minutes before I went home, and it works OK.

I tested it by running "telnet 127.0.0.1 1001" from the DOS prompt twice. The 1st connects, the 2nd doesn't.

I hope it works for you too.

Gotta run now.....

Bob.


#include <winsock.h>

void StartupWinSock()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;

wVersionRequested = MAKEWORD(2, 0);

err = ::WSAStartup(wVersionRequested, &wsaData);
}

void CSimplesockDlg::OnButton1()
{
StartupWinSock();

SOCKET s1 = socket(PF_INET, SOCK_STREAM, 0);

if (s1 == INVALID_SOCKET)
{
AfxMessageBox("error creating socket");
return;
}

struct sockaddr_in serv_addr;

memset((char *)&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(1001);

if (bind(s1, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0)
{
AfxMessageBox("error binding socket");
return;
}

if (listen(s1, 1) == SOCKET_ERROR)
{
AfxMessageBox("error listening on socket");
return;
}

SOCKET s2 = accept(s1, 0, 0);

if (s2 == INVALID_SOCKET)
{
if (WSAGetLastError() != WSAEWOULDBLOCK)
{
AfxMessageBox("error accepting socket");
return;
}
}

closesocket(s1);

// DO stuff with s2
// No new clients should be able to connect
// The Sleep is just so that my simple server does not immediately close down, in real life, you would do you code here.
Sleep(60000);
}
GeneralRe: listen() problem Pin
lucy9-Apr-02 7:17
lucy9-Apr-02 7:17 
GeneralRe: listen() problem Pin
Bob Groves9-Apr-02 22:20
Bob Groves9-Apr-02 22:20 
GeneralRe: listen() problem Pin
lucy10-Apr-02 3:05
lucy10-Apr-02 3:05 
Generalheader file used to access database in C++ Pin
tongc8-Apr-02 2:53
tongc8-Apr-02 2:53 
GeneralRe: header file used to access database in C++ Pin
Christian Graus8-Apr-02 3:00
protectorChristian Graus8-Apr-02 3:00 
GeneralRe: header file used to access database in C++ Pin
tongc8-Apr-02 3:07
tongc8-Apr-02 3:07 
GeneralCEdit Text Alignment Pin
Alex Deem8-Apr-02 2:37
Alex Deem8-Apr-02 2:37 
GeneralScroll bar in TreeCtrl Pin
8-Apr-02 2:33
suss8-Apr-02 2:33 
QuestionWhere comes the prerolling filter? Pin
Lizp8-Apr-02 2:13
Lizp8-Apr-02 2:13 
QuestionHow to get system color? Pin
Feng Qin8-Apr-02 1:30
Feng Qin8-Apr-02 1:30 
AnswerRe: How to get system color? Pin
8-Apr-02 1:44
suss8-Apr-02 1:44 
GeneralRe: How to get system color? Pin
Feng Qin8-Apr-02 1:49
Feng Qin8-Apr-02 1:49 
Questionhow can get the CPU info! Pin
wangyiming8-Apr-02 1:02
wangyiming8-Apr-02 1:02 
AnswerRe: how can get the CPU info! Pin
Lizp8-Apr-02 2:13
Lizp8-Apr-02 2:13 
GeneralRe: how can get the CPU info! Pin
wangyiming8-Apr-02 19:01
wangyiming8-Apr-02 19:01 
GeneralUndeclared Identifier Pin
7-Apr-02 22:55
suss7-Apr-02 22:55 
GeneralRe: Undeclared Identifier Pin
7-Apr-02 23:09
suss7-Apr-02 23:09 

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.