本文整理汇总了C++中setSocket函数的典型用法代码示例。如果您正苦于以下问题:C++ setSocket函数的具体用法?C++ setSocket怎么用?C++ setSocket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setSocket函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strlen
void CSocketControl::setSocket(char* inputString)
{
if (inputString == 0) return;
uint8_t len = strlen(inputString);
if (len < 2 || len > 10) return;
// interpret commands
if (!strcmp(inputString, "alloff"))
for (int i = 1; i <= 4; i++)
setSocket(i, 1);
else
if (!strcmp(inputString, "allon"))
for (int i = 1; i <= 4; i++)
setSocket(i, 0);
else
if (!strcmp(inputString, "looptest"))
test_loop();
else
{
uint8_t socket = 9;
uint8_t state = 0;
socket = inputString[0] - 48;
state = inputString[1] - 49;
setSocket(socket, state);
}
}
示例2: QSocket
ClientSocket::ClientSocket( int sock, InfoData *i, QObject *parent, const char *name ) :
QSocket( parent, name ), info( i )
{
connect( this, SIGNAL(readyRead()), SLOT(readClient()) );
connect( this, SIGNAL(connectionClosed()), SLOT(connectionClosed()) );
setSocket( sock );
}
示例3: setSocket
void ProtocolSocket::socketDisconnected()
{
if (!m_socket)
return;
setSocket(0);
}
示例4: QXmppStream
QXmppIncomingClient::QXmppIncomingClient (QSslSocket *socket, const QString &domain, QObject *parent)
: QXmppStream (parent)
{
bool check;
Q_UNUSED (check);
d = new QXmppIncomingClientPrivate (this);
d->domain = domain;
if (socket)
{
check = connect (socket, SIGNAL (disconnected()),
this, SLOT (onSocketDisconnected()));
Q_ASSERT (check);
setSocket (socket);
}
info (QString ("Incoming client connection from %1").arg (d->origin()));
// create inactivity timer
d->idleTimer = new QTimer (this);
d->idleTimer->setSingleShot (true);
check = connect (d->idleTimer, SIGNAL (timeout()),
this, SLOT (onTimeout()));
Q_ASSERT (check);
}
示例5: MSocketDevice
MMulticastSocketDevice::MMulticastSocketDevice(
QString sAddress, quint16 nPort, u_char ttl) :
MSocketDevice(MSocketDevice::Datagram),
m_address(sAddress), m_port(nPort)
{
#if 0
ttl = UPnp::GetConfiguration()->GetValue( "UPnP/TTL", 4 );
#endif
if (ttl == 0)
ttl = 4;
setProtocol(IPv4);
setSocket(createNewSocket(), MSocketDevice::Datagram);
m_imr.imr_multiaddr.s_addr = inet_addr(sAddress.toLatin1().constData());
m_imr.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(socket(), IPPROTO_IP, IP_ADD_MEMBERSHIP,
(const char *)&m_imr, sizeof( m_imr )) < 0)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "setsockopt - IP_ADD_MEMBERSHIP " + ENO);
}
if (setsockopt(socket(), IPPROTO_IP, IP_MULTICAST_TTL,
(const char *)&ttl, sizeof(ttl)) < 0)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "setsockopt - IP_MULTICAST_TTL " + ENO);
}
setAddressReusable(true);
if (!bind(m_address, m_port))
LOG(VB_GENERAL, LOG_ERR, LOC + "bind failed");
}
示例6: createNode
void createNode(clientNode ** head, int sock, int * size) {
clientNode * node = NULL;
if (*head == NULL) {
node = NULL;
} else {
node = *head;
}
if (node == NULL) {
node = malloc(sizeof(clientNode));
setSocket(&(node->client), sock);
setActive(&(node->client), TRUE);
node->client.name = NULL;
node->next = NULL;
node->prev = NULL;
(*size)++;
*head = node;
} else {
createNode(&((*head)->prev->next), sock, size);
(*head)->prev->next->prev = (*head)->prev;
(*head)->prev = node->prev->next;
}//END IF
}//END FUNCTION
示例7: gethostbyname
bool MinosServerConnection::ioConnect ( const std::string &server, int port )
{
int sock = -1;
int tmp;
struct hostent *host;
struct sockaddr_in sin;
host = gethostbyname ( server.c_str() );
if ( !host )
return false;
memcpy ( &sin.sin_addr, host->h_addr, host->h_length );
sin.sin_family = host->h_addrtype;
sin.sin_port = htons ( port );
sock = socket ( host->h_addrtype, SOCK_STREAM, 0 );
if ( sock == -1 )
return false;
tmp = connect ( sock, ( struct sockaddr * ) & sin, sizeof ( struct sockaddr_in ) );
if ( tmp != 0 )
{
closesocket( sock );
return false;
}
setSocket( sock );
txConnection = true;
return true;
}
示例8: printf
void SpyMini::connectToTank(){
WSADATA wsa;
SOCKET s;
struct sockaddr_in server;
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
{
printf("Failed. Error Code : %d", WSAGetLastError());
return;
}
//Create a socket
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
printf("Could not create socket : %d", WSAGetLastError());
}
printf("Socket created.\n");
server.sin_addr.s_addr = inet_addr("10.10.1.1");
server.sin_family = AF_INET;
server.sin_port = htons(8150);
//Connect to remote server
if (connect(s, (struct sockaddr *)&server, sizeof(server)) < 0)
{
puts("connect error");
return;
}
puts("Connected");
setSocket(s);
}
示例9: httpTransport
// Client constructor.
secureHttpTransport::secureHttpTransport(LogWrapperType _logwrapper,
btg::core::externalization::Externalization* _e,
btg::core::os::gtlsClientData* _gcd,
t_int const _bufferSize,
DIRECTION const _direction,
addressPort const & _addressPort,
t_uint const _timeout)
: httpTransport(_logwrapper, _e, _bufferSize, _direction, _addressPort, false, _timeout)
{
try
{
btg::core::os::SecureClientSocket* tempClient =
new btg::core::os::SecureClientSocket(logWrapper(),
_gcd,
_addressPort.getIp(),
_addressPort.getPort()
);
// When calling the httpTransport initializer we
// created a ClientSocket. This will be deleted in
// this setSocket call.
setSocket(tempClient);
}
catch (btg::core::os::socketException& _se)
{
initialized = false;
#if BTG_TRANSPORT_DEBUG
BTG_NOTICE(logWrapper(), "Failed to init client: " << _se.description());
#endif // BTG_TRANSPORT_DEBUG
}
}
示例10: ConnectionTCPServer
ConfigInterface::ConfigInterface(const std::string &sockfile, const LogSink &logInstance) : ConnectionTCPServer(this, logInstance, "localhost", -1) {
// Create UNIX socket
int m_socket;
socklen_t length;
struct sockaddr_un local;
m_loaded = false;
m_socketId = 0;
m_admin = new AdhocAdmin();
registerHandler(m_admin);
if ((m_socket = getUnixSocket()) == -1)
Log("ConfigInterface", "Could not create UNIX socket: " << strerror(errno));
local.sun_family = AF_UNIX;
strcpy(local.sun_path, sockfile.c_str());
unlink(local.sun_path);
length = offsetof(struct sockaddr_un, sun_path) + strlen(sockfile.c_str());
if (bind(m_socket, (struct sockaddr *) &local, length) == -1) {
Log("ConfigInterface", "Could not bind to UNIX socket: " << sockfile << " " << strerror(errno));
return;
}
if (listen(m_socket, 5) == -1) {
Log("ConfigInterface", "Could not listen to UNIX socket: " << sockfile << " " << strerror(errno));
return;
}
setSocket(m_socket);
m_socketId = purple_input_add(m_socket, PURPLE_INPUT_READ, gotData, this);
m_loaded = true;
}
示例11: connect
void CommunicationTcpSocketServer::newConnection()
{
QTcpSocket *newSocket = serverSocket.nextPendingConnection();
if (newSocket)
{
if (newSocket->isOpen()) {
connect(newSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
}
setSocket(newSocket);
qWarning() << "Új kapcsolat létesült.\n";
QByteArray ba;
ba[0]=0x00;
ba[1]=0x55;
ba[2]=100;
ba[3]=122;
send(ba);
ba[0]=0x00;
ba[1]=0xAA;
ba[2]=128;
ba[3]=14;
send(ba);
ba[0]=0x00;
ba[1]=0xCB;
ba[2]=15;
ba[3]=192;
send(ba);
}
}
示例12: startListening
int eServerSocket::startListening(struct addrinfo *addr)
{
struct addrinfo *ptr = addr;
for (ptr = addr; ptr != NULL; ptr = ptr->ai_next)
{
if (setSocket(socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol), 1) < 0)
{
continue;
}
int val = 1;
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
if (bind(getDescriptor(), ptr->ai_addr, ptr->ai_addrlen) < 0)
{
eDebug("[eServerSocket] ERROR on bind: %m");
close();
continue;
}
}
if (getDescriptor() < 0)
{
return -1;
}
if (listen(getDescriptor(), 0) < 0)
{
close();
return -1;
}
return 0;
}
示例13: address
//! \brief Creates a Connecting Peer
Peer::Peer(PeerWireSocket *socket)
: address(socket->getPeerAddress()), port(socket->getPeerPort()), socket(0),
state(UnconnectedState), suspended(false)
{
setSocket(socket);
setState(ConnectingState);
}
示例14: QObject
NetworkLink::NetworkLink(QTcpSocket *socket)
: QObject(NULL),m_mainWindow(NULL)
{
m_mainWindow = MainWindow::getInstance();
m_networkManager = m_mainWindow->getNetWorkManager();
m_socketTcp = socket;
receptionEnCours = false;
ReceiveEvent::registerNetworkReceiver(NetMsg::PictureCategory,m_mainWindow);
ReceiveEvent::registerNetworkReceiver(NetMsg::MapCategory,m_mainWindow);
ReceiveEvent::registerNetworkReceiver(NetMsg::NPCCategory,m_mainWindow);
ReceiveEvent::registerNetworkReceiver(NetMsg::DrawCategory,m_mainWindow);
ReceiveEvent::registerNetworkReceiver(NetMsg::CharacterCategory,m_mainWindow);
ReceiveEvent::registerNetworkReceiver(NetMsg::ConnectionCategory,m_mainWindow);
ReceiveEvent::registerNetworkReceiver(NetMsg::CharacterPlayerCategory,m_mainWindow);
#ifndef NULL_PLAYER
m_audioPlayer = AudioPlayer::getInstance();
ReceiveEvent::registerNetworkReceiver(NetMsg::MusicCategory,m_audioPlayer);
#endif
setSocket(socket);
if (PreferencesManager::getInstance()->value("isClient",true).toBool())
{
m_networkManager->ajouterNetworkLink(this);
}
}
示例15: setSocket
Socket::Socket(const Socket &orig) : ucommon::Socket()
{
setSocket();
so = dupSocket(orig.so,orig.state);
if(so == INVALID_SOCKET)
error(errCopyFailed,(char *)"Could not duplicate socket handle",socket_errno);
state = orig.state;
}