本文整理汇总了C++中VSocket::Connect方法的典型用法代码示例。如果您正苦于以下问题:C++ VSocket::Connect方法的具体用法?C++ VSocket::Connect怎么用?C++ VSocket::Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VSocket
的用法示例。
在下文中一共展示了VSocket::Connect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
vncSockConnect::~vncSockConnect()
{
m_socket.Shutdown();
// Join with our lovely thread
if (m_thread != NULL)
{
// *** This is a hack to force the listen thread out of the accept call,
// because Winsock accept semantics are broken
((vncSockConnectThread *)m_thread)->m_shutdown = TRUE;
VSocket socket;
socket.Create();
socket.Bind(0);
socket.Connect("localhost", m_port);
socket.Close();
void *returnval;
m_thread->join(&returnval);
m_thread = NULL;
m_socket.Close();
}
}
示例2: vncConnDlgProc
//.........这里部分代码省略.........
ScreenToClient(hwnd, (LPPOINT)lprcEdit);
ScreenToClient(hwnd, ((LPPOINT)lprcEdit)+1);
ScreenToClient(hwnd, (LPPOINT)lprcLabel);
ScreenToClient(hwnd, ((LPPOINT)lprcLabel)+1);
RECT rcClient;
GetClientRect(hwnd, &rcClient);
long nTotalHeight = rcEdit.bottom - rcLabel.top;
long nAdjustedTop = (rcClient.bottom - nTotalHeight) / 2;
long nAdjustment = nAdjustedTop - rcLabel.top;
MoveWindow(hwndLabel, rcLabel.left, rcLabel.top + nAdjustment, rcLabel.right - rcLabel.left, rcLabel.bottom - rcLabel.top, TRUE);
MoveWindow(hwndEdit, rcEdit.left, rcEdit.top + nAdjustment, rcEdit.right - rcEdit.left, rcEdit.bottom - rcEdit.top, TRUE);
HWND hwndCaption = GetDlgItem(hwnd, IDC_CAPTION_STATIC);
HFONT hFont = (HFONT)SendMessage(hwndCaption, WM_GETFONT, 0, 0);
if (hFont) {
LOGFONT lf;
if (GetObject(hFont, sizeof(LOGFONT), &lf)) {
lf.lfWidth = 0;
lf.lfHeight = (lf.lfHeight * 6) / 4;
_this->m_hfont = CreateFontIndirect(&lf);
if (_this->m_hfont) {
SendMessage(hwndCaption, WM_SETFONT, (WPARAM)_this->m_hfont, (LPARAM)TRUE);
}
}
}
SetWindowText(hwndCaption, "Connect to Technical Support");
ShowWindow(hwndCaption, SW_SHOWNA);
}
SetFocus(GetDlgItem(hwnd, IDC_IDCODE));
} else {
// Make the text entry box active
SetFocus(GetDlgItem(hwnd, IDC_HOSTNAME_EDIT));
}
SetForegroundWindow(hwnd);
// Return success!
return TRUE;
}
// Dialog has just received a command
case WM_COMMAND:
switch (LOWORD(wParam))
{
// User clicked OK or pressed return
case IDOK:
{
// [email protected] - host:num & host::num analyse.
// Compatible with both RealVNC and TightVNC methods
char hostname[_MAX_PATH];
char actualhostname[_MAX_PATH];
char idcode[_MAX_PATH];
char *portp;
int port;
bool id;
// Get the hostname of the VNCviewer
示例3: WndProc
//.........这里部分代码省略.........
if (iMsg == MENU_ABOUTBOX_SHOW)
{
// External request to show our About dialog
PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_ABOUT, 0), 0);
return 0;
}
if (iMsg == MENU_SERVICEHELPER_MSG)
{
// External ServiceHelper message.
// This message holds a process id which we can use to
// impersonate a specific user. In doing so, we can load their
// preferences correctly
// vncService::ProcessUserHelperMessage(wParam, lParam);
// Modif Jeremy C.
vncService::ProcessUserHelperMessage((WPARAM)&_this->m_server->m_impersonationtoken, lParam);
// - Trigger a check of the current user
PostMessage(hwnd, WM_USERCHANGED, 0, 0);
return 0;
}
if (iMsg == RETRY_MESSAGE)
{
connect_counter++;
if (connect_counter%5==0)
{
// Attempt to create a new socket
// Beep(1000,100);
VSocket *tmpsock;
tmpsock = new VSocket;
if (tmpsock) {
// Connect out to the specified host on the VNCviewer listen port
tmpsock->Create();
if (tmpsock->Connect(szAdrName, nport)) {
// Add the new client to this server
if (strcmp(g_idcode,"")==NULL) g_id=false;
else g_id=true;
char sendID[_MAX_PATH];
strcpy(sendID,"ID:");
strcat(sendID,g_idcode);
if (g_id)
tmpsock->Send(sendID,250);
_this->m_server->AddClient(tmpsock, TRUE, TRUE);
nport=0;
connected=1;
_this->FlashTrayIcon(_this->m_server->AuthClientCount() != 0);
return 0;
} else {
delete tmpsock;
connect_counter++;
if (connect_counter>25)
// Sleep(5000);
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
}
}
return 0;
}
if (iMsg == MENU_ADD_CLIENT_MSG)
{
// [email protected] - Autoreconnect
// Dirty trick to avoid to add a new MSG... no time
if (lParam == 999)
{
_this->m_server->AutoReconnect(true);
示例4: vncConnDlgProc
BOOL CALLBACK vncConnDialog::vncConnDlgProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam) {
// This is a static method, so we don't know which instantiation we're
// dealing with. But we can get a pseudo-this from the parameter to
// WM_INITDIALOG, which we therafter store with the window and retrieve
// as follows:
vncConnDialog *_this = (vncConnDialog *) GetWindowLong(hwnd, GWL_USERDATA);
switch (uMsg) {
// Dialog has just been created
case WM_INITDIALOG:
{
// Save the lParam into our user data so that subsequent calls have
// access to the parent C++ object
SetWindowLong(hwnd, GWL_USERDATA, lParam);
vncConnDialog *_this = (vncConnDialog *) lParam;
// Make the text entry box active
SetFocus(GetDlgItem(hwnd, IDC_HOSTNAME_EDIT));
// Return success!
return TRUE;
}
// Dialog has just received a command
case WM_COMMAND:
switch (LOWORD(wParam)) {
// User clicked OK or pressed return
case IDOK:
{
char viewer[256];
char hostname[256];
VCard display_or_port;
// Get the viewer to connect to
GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, viewer, 256);
// Process the supplied viewer address
int result = sscanf(viewer, "%255[^:]:%u", hostname, &display_or_port);
if (result == 1) {
display_or_port = 0;
result = 2;
}
if (result == 2) {
// Correct a display number to a port number if required
if (display_or_port < 100) {
display_or_port += INCOMING_PORT_OFFSET;
}
// Attempt to create a new socket
VSocket *tmpsock;
tmpsock = new VSocket;
if (!tmpsock)
return TRUE;
// Connect out to the specified host on the VNCviewer listen port
// To be really good, we should allow a display number here but
// for now we'll just assume we're connecting to display zero
tmpsock->Create();
if (tmpsock->Connect(hostname, display_or_port)) {
// Add the new client to this server
_this->m_server->AddClient(tmpsock, TRUE, TRUE);
// And close the dialog
EndDialog(hwnd, TRUE);
} else {
// Print up an error message
MessageBox(NULL,
"Failed to connect to listening VNC viewer",
"Outgoing Connection",
MB_OK | MB_ICONEXCLAMATION );
delete tmpsock;
}
} else {
// We couldn't process the machine specification
MessageBox(NULL, "Unable to process specified hostname and display/port",
"Outgoing Connection", MB_OK | MB_ICONEXCLAMATION);
}
}
return TRUE;
// Cancel the dialog
case IDCANCEL:
EndDialog(hwnd, FALSE);
return TRUE;
};
break;
case WM_DESTROY:
EndDialog(hwnd, FALSE);
return TRUE;
}
return 0;
}
示例5: vncSockConnect
// Socket connection handling
BOOL
vncServer::SockConnect(BOOL On)
{
// Are we being asked to switch socket connects on or off?
if (On)
{
// Is there a listening socket?
if (m_socketConn == NULL)
{
m_socketConn = new vncSockConnect();
if (m_socketConn == NULL)
return FALSE;
// Are we to use automatic port selection?
if (m_autoportselect)
{
BOOL ok = FALSE;
// Yes, so cycle through the ports, looking for a free one!
for (int i=0; i < 99; i++)
{
m_port = DISPLAY_TO_PORT(i);
vnclog.Print(LL_CLIENTS, VNCLOG("trying port number %d\n"), m_port);
// Attempt to connect to the port
VSocket tempsock;
if (tempsock.Create())
{
if (!tempsock.Connect("localhost", m_port))
{
// Couldn't connect, so this port is probably usable!
if (m_socketConn->Init(this, m_port))
{
ok = TRUE;
break;
}
}
}
}
if (!ok)
{
delete m_socketConn;
m_socketConn = NULL;
return FALSE;
}
} else
{
// No autoportselect
if (!m_socketConn->Init(this, m_port))
{
delete m_socketConn;
m_socketConn = NULL;
return FALSE;
}
}
}
}
else
{
// *** JNW - Trying to fix up a lock-up when the listening socket closes
KillAuthClients();
KillUnauthClients();
WaitUntilAuthEmpty();
WaitUntilUnauthEmpty();
// Is there a listening socket?
if (m_socketConn != NULL)
{
// Close the socket
delete m_socketConn;
m_socketConn = NULL;
}
}
return TRUE;
}
示例6: WndProc
//.........这里部分代码省略.........
strcpy(szAdrName, nameDup);
// Free the duplicate name
if (nameDup != 0) free(nameDup);
// Get the port number
nport = (unsigned short)wParam;
if (nport == 0)
nport = INCOMING_PORT_OFFSET;
}
// [email protected] -- added support for the AutoReconnectId
// (but it's not required)
bool bId = ( strlen(_this->m_server->AutoReconnectId() ) > 0);
if ( bId )
strcpy( szId, _this->m_server->AutoReconnectId() );
// [email protected]
// Stores the client adr/ports the first time we try to connect
// This way we can call this message again later to reconnect with the same values
if ((_this->m_server->AutoReconnect() || _this->m_server->IdReconnect())&& strlen(_this->m_server->AutoReconnectAdr()) == 0)
{
_this->m_server->AutoReconnectAdr(szAdrName);
_this->m_server->AutoReconnectPort(nport);
}
// Attempt to create a new socket
VSocket *tmpsock;
tmpsock = new VSocket;
if (tmpsock) {
// Connect out to the specified host on the VNCviewer listen port
tmpsock->Create();
if (tmpsock->Connect(szAdrName, nport)) {
if ( bId )
{
// [email protected] -- added support for the AutoReconnectId
// Set the ID for this client -- code taken from vncconndialog.cpp (ln:142)
tmpsock->Send(szId,250);
tmpsock->SetTimeout(0);
// adzm 2009-07-05 - repeater IDs
// Add the new client to this server
// adzm 2009-08-02
_this->m_server->AddClient(tmpsock, TRUE, TRUE, 0, NULL, szId, szAdrName, nport);
} else {
// Add the new client to this server
// adzm 2009-08-02
_this->m_server->AddClient(tmpsock, TRUE, TRUE, 0, NULL, NULL, szAdrName, nport);
}
} else {
delete tmpsock;
_this->m_server->AutoConnectRetry();
}
}
return 0;
}
// Process FileTransfer asynchronous Send Packet Message
if (iMsg == FileTransferSendPacketMessage)
{
vncClient* pClient = (vncClient*) wParam;
if (_this->m_server->IsClient(pClient)) pClient->SendFileChunk();
}
示例7: WinVNCDll_ListenForClient
//.........这里部分代码省略.........
ZeroMemory(finalidcode, sizeof(finalidcode));
//adzm 2009-06-20
if (id) {
size_t i = 0;
for (i = 0; i < strlen(idcode); i++)
{
finalidcode[i] = toupper(idcode[i]);
}
finalidcode[i] = 0;
if (0 != strncmp("ID:", idcode, 3)) {
strcpy(finalidcode, "ID:");
for (i = 0; i < strlen(idcode); i++)
{
finalidcode[i+3] = toupper(idcode[i]);
}
finalidcode[i+3] = 0;
}
//adzm 2010-02-15 - At this point, finalidcode is of the form "ID:#####"
int numericId = atoi(finalidcode + 3);
int numberOfHosts = 1;
for (i = 0; i < strlen(hostname); i++) {
if (hostname[i] == ';') {
numberOfHosts++;
}
}
if (numberOfHosts <= 1) {
// then hostname == actualhostname
} else {
int modulo = numericId % numberOfHosts;
char* szToken = strtok(hostname, ";");
while (szToken) {
if (modulo == 0) {
strcpy(actualhostname, szToken);
break;
}
modulo--;
szToken = strtok(NULL, ";");
}
}
}
// Calculate the Display and Port offset.
port = INCOMING_PORT_OFFSET;
portp = strchr(actualhostname, ':');
if (portp)
{
*portp++ = '\0';
if (*portp == ':') // Tight127 method
{
port = atoi(++portp); // Port number after "::"
}
else // RealVNC method
{
if (atoi(portp) < 100) // If < 100 after ":" -> display number
port += atoi(portp);
else
port = atoi(portp); // If > 100 after ":" -> Port number
}
}
// Attempt to create a new socket
VSocket *tmpsock;
tmpsock = new VSocket;
if (!tmpsock) {
vnclog.Print(LL_STATE, VNCLOG("Could not create socket\n"));
return -1;
}
// Connect out to the specified host on the VNCviewer listen port
// To be really good, we should allow a display number here but
// for now we'll just assume we're connecting to display zero
tmpsock->Create();
vnclog.Print(LL_STATE, VNCLOG("Connecting to: %s %d\n"),actualhostname,port);
if (tmpsock->Connect(actualhostname, port))
{
vnclog.Print(LL_STATE, VNCLOG("Adding client: %s %d\n"),actualhostname,port);
if (id)
{
tmpsock->Send(finalidcode,250);
tmpsock->SetTimeout(0);
// adzm 2009-07-05 - repeater IDs
// Add the new client to this server
// adzm 2009-08-02
return m_server->AddClient(tmpsock, TRUE, TRUE, 0, NULL, finalidcode, actualhostname, port);
} else {
// Add the new client to this server
// adzm 2009-08-02
return m_server->AddClient(tmpsock, TRUE, TRUE, 0, NULL, NULL, actualhostname, port);
}
}
}
示例8: vncSockConnect
// Socket connection handling
BOOL
vncServer::SockConnect(BOOL On)
{
// Are we being asked to switch socket connects on or off?
if (On)
{
// Is there a listening socket?
if (m_socketConn == NULL)
{
m_socketConn = new vncSockConnect();
if (m_socketConn == NULL)
return FALSE;
// Are we to use automatic port selection?
if (m_autoportselect)
{
BOOL ok = FALSE;
// Yes, so cycle through the ports, looking for a free one!
for (int i = 0; i < 99; i++)
{
m_port = DISPLAY_TO_PORT(i);
m_port_http = DISPLAY_TO_HPORT(i);
vnclog.Print(LL_CLIENTS, VNCLOG("trying port number %d\n"), m_port);
// Attempt to connect to the port
VSocket tempsock;
if (tempsock.Create())
{
if (!tempsock.Connect("localhost", m_port))
{
// Couldn't connect, so this port is probably usable!
if (m_socketConn->Init(this, m_port))
{
ok = TRUE;
break;
}
}
}
}
if (!ok)
{
delete m_socketConn;
m_socketConn = NULL;
return FALSE;
}
} else
{
// No autoportselect
if (!m_socketConn->Init(this, m_port))
{
delete m_socketConn;
m_socketConn = NULL;
return FALSE;
}
}
// Now let's start the HTTP connection stuff
if (m_port_http == m_port) {
vnclog.Print(LL_INTERR, VNCLOG("cannot start both RFB and HTTP servers "
"on the same port\n"));
}
if (m_httpConn == NULL && m_httpd_enabled && m_port_http != m_port) {
m_httpConn = new vncHTTPConnect;
if (m_httpConn != NULL) {
// Start up the HTTP server
if (!m_httpConn->Init(this, m_port_http,
m_httpd_params_enabled)) {
delete m_httpConn;
m_httpConn = NULL;
return FALSE;
}
}
}
}
}
else
{
// *** JNW - Trying to fix up a lock-up when the listening socket closes
#ifndef HORIZONLIVE
KillAuthClients();
KillUnauthClients();
WaitUntilAuthEmpty();
WaitUntilUnauthEmpty();
#endif
// Is there a listening socket?
if (m_socketConn != NULL)
{
// Close the socket
delete m_socketConn;
m_socketConn = NULL;
}
// Is there an HTTP socket active?
if (m_httpConn != NULL)
{
//.........这里部分代码省略.........