• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ setSocket函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中setSocket函数的典型用法代码示例。如果您正苦于以下问题:C++ setSocket函数的具体用法?C++ setSocket怎么用?C++ setSocket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了setSocket函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
        }
}
开发者ID:ioanpaulpirau,项目名称:SmartPowerExtender,代码行数:27,代码来源:Utils.cpp


示例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 );
}
开发者ID:aroraujjwal,项目名称:qt3,代码行数:7,代码来源:server.cpp


示例3: setSocket

void ProtocolSocket::socketDisconnected()
{
    if (!m_socket)
        return;

    setSocket(0);
}
开发者ID:FreshDev,项目名称:torsion,代码行数:7,代码来源:ProtocolSocket.cpp


示例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);
}
开发者ID:glwu,项目名称:WinT-Messenger,代码行数:27,代码来源:QXmppIncomingClient.cpp


示例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");
}
开发者ID:aravilife,项目名称:mythtv-stabilize2,代码行数:35,代码来源:mmulticastsocketdevice.cpp


示例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
开发者ID:mic1780,项目名称:websockets,代码行数:25,代码来源:libfunctions.c


示例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;
}
开发者ID:BackupTheBerlios,项目名称:minos-svn,代码行数:31,代码来源:serverThread.cpp


示例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);
	
}
开发者ID:detik19,项目名称:I-SpyMiniTankMeetOpenCV,代码行数:30,代码来源:SpyMini.cpp


示例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
            }
      }
开发者ID:BackupTheBerlios,项目名称:btg-svn,代码行数:33,代码来源:shttp.cpp


示例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;
}
开发者ID:bochi,项目名称:spectrum-gw,代码行数:35,代码来源:configinterface.cpp


示例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);

    }
}
开发者ID:koincidencia,项目名称:MotorControllerSimulator,代码行数:33,代码来源:CommunicationTcpSocketServer.cpp


示例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;
}
开发者ID:kingvuplus,项目名称:PE-gui,代码行数:33,代码来源:serversocket.cpp


示例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);
}
开发者ID:Etrnls,项目名称:evangel,代码行数:8,代码来源:peer.cpp


示例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);
    }
}
开发者ID:hfiguiere,项目名称:rolisteam,代码行数:26,代码来源:networklink.cpp


示例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;
}
开发者ID:oudream,项目名称:ucommon,代码行数:8,代码来源:socket.cpp


示例16: readbuffer

eSocket::eSocket(eMainloop *ml, int domain): readbuffer(32768), writebuffer(32768), rsn(0), mainloop(ml)
{
	int s=socket(domain, SOCK_STREAM, 0);
#if 0
	eDebug("[SOCKET]: initalized socket %d", socketdesc);
#endif
	mystate=Idle;
	setSocket(s, 1, ml);
}
开发者ID:ChakaZulu,项目名称:tuxbox_apps,代码行数:9,代码来源:socket.cpp


示例17: lock

	CARIBOU::CUdpSocket& CUdpSession::takeSocket()
	{
		lock();
		if ( socketQueue().count() )
		{
			setSocket(socketQueue().takeFirst());
		}
		unlock();
		return mSocket;
	}
开发者ID:8bitgeek,项目名称:caribou-rtos,代码行数:10,代码来源:cudpsession.cpp


示例18: Q_UNUSED

void Session::setSecure(bool secure)
{
#ifdef QT_NO_OPENSSL
    Q_UNUSED(secure)
#else
    QSslSocket* sslSocket = qobject_cast<QSslSocket*>(socket());
    if (secure && !sslSocket)
    {
        sslSocket = new QSslSocket(this);
        sslSocket->setPeerVerifyMode(QSslSocket::VerifyNone);
        sslSocket->ignoreSslErrors();
        setSocket(sslSocket);
    }
    else if (!secure && sslSocket)
    {
        setSocket(new QTcpSocket(this));
    }
#endif // QT_NO_OPENSSL
}
开发者ID:EldFitheach,项目名称:Mudlet,代码行数:19,代码来源:session.cpp


示例19: Connection

LocalSocketConnection::LocalSocketConnection(QObject *parentObject,
                                             const QString &serverName)
  : Connection(parentObject),
    m_connectionString(serverName),
    m_socket(NULL),
    m_dataStream(new QDataStream),
    m_holdRequests(true)
{
  setSocket(new QLocalSocket);
}
开发者ID:OpenChemistry,项目名称:molequeue,代码行数:10,代码来源:localsocketconnection.cpp


示例20: using

/*!
    Creates a QSocketDevice object for a stream or datagram socket.

    The \a type argument must be either \c QSocketDevice::Stream for a
    reliable, connection-oriented TCP socket, or \c
    QSocketDevice::Datagram for an unreliable UDP socket.

    The \a protocol indicates whether the socket should be of type IPv4
    or IPv6. Passing \c Unknown is not meaningful in this context and you
    should avoid using (it creates an IPv4 socket, but your code is not easily
    readable).

    The argument \a dummy is necessary for compatibility with some
    compilers.

    \sa blocking() protocol()
*/
QSocketDevice::QSocketDevice( Type type, Protocol protocol, int )
    : fd( -1 ), t( type ), p( 0 ), pp( 0 ), e( NoError ),
      d(new QSocketDevicePrivate(protocol))
{
#if defined(QSOCKETDEVICE_DEBUG)
    qDebug( "QSocketDevice: Created QSocketDevice object %p, type %d",
	    this, type );
#endif
    init();
    setSocket( createNewSocket(), type );
}
开发者ID:OS2World,项目名称:LIB-QT3_Toolkit_Vbox,代码行数:28,代码来源:qsocketdevice.cpp



注:本文中的setSocket函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ setSorting函数代码示例发布时间:2022-05-30
下一篇:
C++ setSliderPosition函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap