Ejemplo n.º 1
0
TEST(AsyncSocketTest, duplicateBind) {
  EventBase base;
  auto server1 = AsyncServerSocket::newSocket(&base);
  server1->bind(0);
  server1->listen(10);

  SocketAddress address;
  server1->getAddress(std::addressof(address));

  auto server2 = AsyncServerSocket::newSocket(&base);
  EXPECT_THROW(server2->bind(address.getPort()), std::exception);
}
Ejemplo n.º 2
0
HTTPClientSession::HTTPClientSession(const SocketAddress& address):
	_host(address.host().toString()),
	_port(address.port()),
	_proxyPort(HTTPSession::HTTP_PORT),
	_keepAliveTimeout(DEFAULT_KEEP_ALIVE_TIMEOUT, 0),
	_reconnect(false),
	_mustReconnect(false),
	_expectResponseBody(false),
	_pRequestStream(0),
	_pResponseStream(0)
{
}
Ejemplo n.º 3
0
nsapi_size_or_error_t AT_CellularStack::socket_sendto(nsapi_socket_t handle, const SocketAddress &addr, const void *data, unsigned size)
{
    CellularSocket *socket = (CellularSocket *)handle;
    if (!socket) {
        return NSAPI_ERROR_DEVICE_ERROR;
    }

    if (socket->closed && !socket->rx_avail) {
        tr_info("sendto socket %d closed", socket->id);
        return NSAPI_ERROR_NO_CONNECTION;
    }

    if (size == 0) {
        if (socket->proto == NSAPI_UDP) {
            return NSAPI_ERROR_UNSUPPORTED;
        } else if (socket->proto == NSAPI_TCP) {
            return 0;
        }
    }

    nsapi_size_or_error_t ret_val = NSAPI_ERROR_OK;

    if (!socket->created) {
        _at.lock();

        ret_val = create_socket_impl(socket);

        _at.unlock();
        if (ret_val != NSAPI_ERROR_OK) {
            tr_error("Socket %d create %s error %d", find_socket_index(socket), addr.get_ip_address(), ret_val);
            return ret_val;
        }
    }

    /* Check parameters */
    if (addr.get_ip_version() == NSAPI_UNSPEC) {
        return NSAPI_ERROR_DEVICE_ERROR;
    }

    _at.lock();

    ret_val = socket_sendto_impl(socket, addr, data, size);

    _at.unlock();

    if (ret_val >= 0) {
        tr_info("Socket %d sent %d bytes to %s port %d", find_socket_index(socket), ret_val, addr.get_ip_address(), addr.get_port());
    } else if (ret_val != NSAPI_ERROR_WOULD_BLOCK) {
        tr_error("Socket %d sendto %s error %d", find_socket_index(socket), addr.get_ip_address(), ret_val);
    }

    return ret_val;
}
Ejemplo n.º 4
0
void TCPServerSocket::bind(const SocketAddress &localAddress) 
  throw(SocketException) {
  createSocket(localAddress, SOCK_STREAM, IPPROTO_TCP);

  if (::bind(sockDesc, localAddress.getSockaddr(), 
             localAddress.getSockaddrLen()) < 0)
    throw SocketException(string("Call to bind() failed :  ") +
                          strerror(errno));

  // This is temporary.
  setListen(5);
}
Ejemplo n.º 5
0
nsapi_size_or_error_t UDPSocket::sendto(const char *host, uint16_t port, const void *data, nsapi_size_t size)
{
    SocketAddress address;
    nsapi_size_or_error_t err = _stack->gethostbyname(host, &address);
    if (err) {
        return NSAPI_ERROR_DNS_FAILURE;
    }

    address.set_port(port);

    // sendto is thread safe
    return sendto(address, data, size);
}
Ejemplo n.º 6
0
void CheckPrefixMatch(
    const SocketAddress& first,
    const SocketAddress& second,
    unsigned matchingPrefixLen) {
  unsigned i;
  for (i = 0; i <= matchingPrefixLen; i++) {
    EXPECT_TRUE(first.prefixMatch(second, i));
  }
  unsigned addrLen = (first.getFamily() == AF_INET6) ? 128 : 32;
  for (; i <= addrLen; i++) {
    EXPECT_TRUE(!first.prefixMatch(second, i));
  }
}
Ejemplo n.º 7
0
TEST(SocketAddress, IPv4ToStringConversion) {
  // testing addresses *.5.5.5, 5.*.5.5, 5.5.*.5, 5.5.5.*
  SocketAddress addr;
  for (int pos = 0; pos < 4; ++pos) {
    for (int i = 0; i < 256; ++i) {
      auto fragments = folly::make_array(5, 5, 5, 5);
      fragments[pos] = i;
      auto ipString = folly::join(".", fragments);
      addr.setFromIpPort(ipString, 1234);
      EXPECT_EQ(addr.getAddressStr(), ipString);
    }
  }
}
Ejemplo n.º 8
0
void StreamServerSocket::bind( const SocketAddress& sockaddr ) {
    if ( m_fd < 0 ) m_fd = socket( sockaddr.linkProtocol(), SOCK_STREAM, 0 );
    if ( m_fd < 0 ) {
        throw CException("Error creating socket", m_fd);
    }
    
	const struct sockaddr* raw = sockaddr.raw();
	socklen_t socklen = sockaddr.rawlen();
    int rc = ::bind( m_fd, raw, socklen );
    if( rc ) {
        throw BindException("Error on bind", errno);
    }
}
Ejemplo n.º 9
0
nsapi_error_t TCPSocket::connect(const char *host, uint16_t port)
{
    SocketAddress address;
    nsapi_error_t err = _stack->gethostbyname(host, &address);
    if (err) {
        return NSAPI_ERROR_DNS_FAILURE;
    }

    address.set_port(port);

    // connect is thread safe
    return connect(address);
}
Ejemplo n.º 10
0
//Al principio el estado de la red es UNINITIALIZED
NetworkClient::NetworkClient(std::string _addressServer, std::string _addressClient, std::string _nick):nick(_nick), networkState(NetworkState::UNINITIALIZED)
{
	saServer.SetAddress(_addressServer);
	SocketAddress myAddress;
	myAddress.SetAddress(_addressClient);
	int errBind = udpSocket.Bind(myAddress);
	int errBlock = udpSocket.NonBlocking(true);
	if (errBind > -1 && errBlock > -1)
	{
		//Si podemos hacer BIND y NONBLOCKING, pasamos a estado SAYINGHELLO
		//Este cliente empezará a buscar al servidor.
		networkState = NetworkState::SAYINGHELLO;
	}
}
Ejemplo n.º 11
0
/*! Spcify the network interface for outgoing multicast
    packages
 */
void DgramSocket::setMCastInterface(const SocketAddress &interf)
{
    int rc = setsockopt(_sd,
                        IPPROTO_IP,
                        IP_MULTICAST_IF,
                        reinterpret_cast<SocketOptT*>(interf.getSockAddr()),
                        interf.getSockAddrSize());

    if(rc < 0)
    {
        throw SocketError("setsockopt(IPPROTO_IP,IP_MULTICAST_IF)");
    }

}
Ejemplo n.º 12
0
int main(int argc, char** argv) {
  gflags::ParseCommandLineFlags(&argc, &argv, true);

  if (FLAGS_port == 0) {
    LOG(ERROR) << "Must specify port";
    exit(EXIT_FAILURE);
  }

  // Prep the socket
  EventBase evb;
  AsyncSocket::UniquePtr socket;
  if (FLAGS_ssl) {
    auto sslContext = std::make_shared<SSLContext>();
    socket = AsyncSocket::UniquePtr(new AsyncSSLSocket(sslContext, &evb));
  } else {
    socket = AsyncSocket::UniquePtr(new AsyncSocket(&evb));
  }
  socket->detachEventBase();

  if (FLAGS_tfo) {
#if FOLLY_ALLOW_TFO
    socket->enableTFO();
#endif
  }

  // Keep this around
  auto sockAddr = socket.get();

  BlockingSocket sock(std::move(socket));
  SocketAddress addr;
  addr.setFromHostPort(FLAGS_host, FLAGS_port);
  sock.setAddress(addr);
  sock.open();
  LOG(INFO) << "connected to " << addr.getAddressStr();

  sock.write((const uint8_t*)FLAGS_msg.data(), FLAGS_msg.size());

  LOG(ERROR) << "TFO attempted: " << sockAddr->getTFOAttempted();
  LOG(ERROR) << "TFO finished: " << sockAddr->getTFOFinished();

  std::array<char, 1024> buf;
  int32_t bytesRead = 0;
  while ((bytesRead = sock.read((uint8_t*)buf.data(), buf.size())) != 0) {
    std::cout << std::string(buf.data(), bytesRead);
  }

  sock.close();
  return 0;
}
Ejemplo n.º 13
0
int ICMPClient::ping(SocketAddress& address, int repeat) const
{
	if (repeat <= 0) return 0;

	ICMPSocket icmpSocket(_family);
	SocketAddress returnAddress;

	ICMPEventArgs eventArgs(address, repeat, icmpSocket.dataSize(), icmpSocket.ttl());
	pingBegin.notify(this, eventArgs);

	for (int i = 0; i < repeat; ++i)
	{
		icmpSocket.sendTo(address);
		++eventArgs;

		try
		{
			int t = icmpSocket.receiveFrom(returnAddress);
			eventArgs.setReplyTime(i, t);
			pingReply.notify(this, eventArgs);
		}
		catch (TimeoutException&)
		{
			std::ostringstream os;
			os << address.host().toString() << ": Request timed out.";
			eventArgs.setError(i, os.str());
			pingError.notify(this, eventArgs);
			continue;
		}
		catch (ICMPException& ex)
		{
			std::ostringstream os;
			os << address.host().toString() << ": " << ex.what();
			eventArgs.setError(i, os.str());
			pingError.notify(this, eventArgs);
			continue;
		}
		catch (Exception& ex)
		{
			std::ostringstream os;
			os << ex.displayText();
			eventArgs.setError(i, os.str());
			pingError.notify(this, eventArgs);
			continue;
		}
	}
	pingEnd.notify(this, eventArgs);
	return eventArgs.received();
}
Ejemplo n.º 14
0
int TCPSocket::bindAddr(SocketAddress &serveraddr)
{
    if( m_iIpType == IPV4)
    {
        struct sockaddr_in addr;
        memset(&addr,0,sizeof(addr));
        addr.sin_family = PF_INET;
        
        if(serveraddr.ifAnyAddr())
            addr.sin_addr.s_addr = htons(INADDR_ANY);
        else if((inet_aton(serveraddr.getIP(),(in_addr *)&addr.sin_addr.s_addr)) == 0)
        {
            handleSyscallError("TCPSocket::bindAddr");
            return FAILED;
        }

        if(serveraddr.getPort()==0)
        {
            handleError("TCPSocket::getPort");
            return FAILED;
        }
        addr.sin_port = htons(serveraddr.getPort());
        if(bind(m_iSockFd,(const struct sockaddr *)&addr,sizeof(addr)) <0)
        {
            handleSyscallError("TCPSocket::bindAddr");
            return FAILED;
        }
    } else 
    {
        struct sockaddr_in6 addr;
        memset(&addr,0,sizeof(addr));
        addr.sin6_family = PF_INET6;
        addr.sin6_scope_id = 2;
        if( serveraddr.ifAnyAddr())
            addr.sin6_addr = in6addr_any;
        else
        {
            if( inet_pton(PF_INET6,serveraddr.getIP(),&(addr.sin6_addr)) < 0)
            {
                handleSyscallError("TCPSocket::bindAddr");
                return FAILED;
            }
            
        }
        
        if(serveraddr.getPort()==0)
        {
            handleError("TCPSocket::getPort");
            return FAILED;
        }
        addr.sin6_port = htons(serveraddr.getPort());
        if(bind(m_iSockFd,(const struct sockaddr *)&addr,sizeof(addr)) <0)
        {
            handleSyscallError("TCPSocket::bindAddr");
            return FAILED;
        }
    }
    return SUCCESSFUL;
}
Ejemplo n.º 15
0
void ServerSocket::listen(const SocketAddress& local, int backlog,
		bool reuseAddr, bool blocking) throw (IOException&)
{
	close();

	int sock = mxos::openSocket(AF_INET, SOCK_STREAM, 0);

	if (-1 == sock)
	{
		THROW3(IOException, "Can't open socket", mxos::getLastSocketError());
	}

	if (reuseAddr)
	{
		int val = 1;

		if (0 != mxos::setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val,
				sizeof(val)))
		{
			mxos::closeSocket(sock);
			THROW3(IOException, "Can't reuse addr", mxos::getLastSocketError());
		}
	}

	if (0 != mxos::bind(sock, local.sockAddress(), local.length()))
	{
		mxos::closeSocket(sock);
		THROW3(IOException, std::string("Can't bind socket to:") + local.toString(), mxos::getLastSocketError());
	}

	if (!blocking)
	{
		try
		{
			IOUtil::configBlocking(sock, false);
		} catch (mxcore::IOException& e)
		{
			mxos::closeSocket(sock);
			throw e;
		}
	}
	if (0 != mxos::listen(sock, backlog))
	{
		mxos::closeSocket(sock);
		THROW3(IOException, "Can't listen socket", mxos::getLastSocketError());
	}

	handle_ = sock;
}
Ejemplo n.º 16
0
void DatagramSocketTest::testSendToReceiveFrom()
{
	UDPEchoServer echoServer(SocketAddress("localhost", 0));
	DatagramSocket ss(SocketAddress::IPv4);
	int n = ss.sendTo("hello", 5, SocketAddress("localhost", echoServer.port()));
	assert (n == 5);
	char buffer[256];
	SocketAddress sa;
	n = ss.receiveFrom(buffer, sizeof(buffer), sa);
	assert (sa.host() == echoServer.address().host());
	assert (sa.port() == echoServer.port());
	assert (n == 5);
	assert (std::string(buffer, n) == "hello");
	ss.close();
}
Ejemplo n.º 17
0
int Socket::listen(const SocketAddress& addr, int backlog) const
{
    createSocket(addr);

    const SOCKET& socket = impl->fd;
    BOOL yes=1;
    QPID_WINSOCK_CHECK(setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)));

    if (::bind(socket, getAddrInfo(addr).ai_addr, getAddrInfo(addr).ai_addrlen) == SOCKET_ERROR)
        throw Exception(QPID_MSG("Can't bind to " << addr.asString() << ": " << strError(WSAGetLastError())));
    if (::listen(socket, backlog) == SOCKET_ERROR)
        throw Exception(QPID_MSG("Can't listen on " <<addr.asString() << ": " << strError(WSAGetLastError())));

    return getLocalPort(socket);
}
Ejemplo n.º 18
0
ssize_t
SocketDescriptor::Write(const void *buffer, size_t length,
                        SocketAddress address)
{
  int flags = 0;
#ifdef HAVE_POSIX
  flags |= MSG_DONTWAIT;
#endif
#ifdef __linux__
  flags |= MSG_NOSIGNAL;
#endif

  return ::sendto(Get(), (const char *)buffer, length, flags,
                  address.GetAddress(), address.GetSize());
}
Ejemplo n.º 19
0
TEST_F (SocketAddressTest, Set)
{
    SocketAddress sa;
    ASSERT_TRUE (sa.SetToLocalhost (AF_INET, 1138));
    ASSERT_STREQ ("127.0.0.1", sa.GetIPAddress ().c_str ());
    ASSERT_EQ (1138, sa.GetPort ());

    ASSERT_TRUE (sa.SetToAnyAddress (AF_INET, 0));
    ASSERT_STREQ ("0.0.0.0", sa.GetIPAddress ().c_str ());
    ASSERT_EQ (0, sa.GetPort ());

    ASSERT_TRUE (sa.SetToLocalhost (AF_INET6, 1139));
    ASSERT_STREQ ("::1", sa.GetIPAddress ().c_str ());
    ASSERT_EQ (1139, sa.GetPort ());
}
Ejemplo n.º 20
0
bool ControlPoint::addPortMapping(PortMapping& pm, Service& wipcs)
{
   bool rval = true;

   // if internal client is not specified, get it by connecting to gateway
   if(!pm->hasMember("NewInternalClient") ||
      pm["NewInternalClient"]->length() == 0)
   {
      // get the control url for the service
      Url url;
      url.format("%s%s",
         wipcs["rootURL"]->getString(),
         wipcs["controlURL"]->getString());
      HttpConnectionRef conn = HttpClient::createConnection(&url);
      if(!conn.isNull())
      {
         SocketAddress* addr = conn->getLocalAddress();
         pm["NewInternalClient"] = addr->getAddress();
         conn->close();
      }
      else
      {
         MO_CAT_ERROR(MO_UPNP_CAT,
            "Could not add port mapping, could not connect to '%s'.",
            url.toString().c_str());
         rval = false;
      }
   }

   if(rval)
   {
      MO_CAT_DEBUG(MO_UPNP_CAT,
         "Adding port mapping: %s", JsonWriter::writeToString(pm).c_str());
   }

   // perform the action
   ActionResult result;
   rval = rval && performAction("AddPortMapping", pm, wipcs, result);
   if(!rval)
   {
      MO_CAT_ERROR(MO_UPNP_CAT,
         "Failed to add port mapping: %s, %s",
         JsonWriter::writeToString(pm).c_str(),
         JsonWriter::writeToString(Exception::getAsDynamicObject()).c_str());
   }

   return rval;
}
Ejemplo n.º 21
0
TEST(SocketAddress, SetFromSocketUnixExplicit) {
  // Pick two temporary path names.
  TemporaryDirectory tempDirectory("SocketAddressTest");
  std::string serverPath = (tempDirectory.path() / "server").string();
  std::string clientPath = (tempDirectory.path() / "client").string();

  SocketAddress serverBindAddr;
  SocketAddress clientBindAddr;
  SocketAddress listenAddr;
  SocketAddress acceptAddr;
  SocketAddress serverAddr;
  SocketAddress serverPeerAddr;
  SocketAddress clientAddr;
  SocketAddress clientPeerAddr;
  try {
    serverBindAddr.setFromPath(serverPath.c_str());
    clientBindAddr.setFromPath(clientPath.c_str());

    testSetFromSocket(
        &serverBindAddr,
        &clientBindAddr,
        &listenAddr,
        &acceptAddr,
        &serverAddr,
        &serverPeerAddr,
        &clientAddr,
        &clientPeerAddr);
  } catch (...) {
    // Remove the socket files after we are done
    unlink(serverPath.c_str());
    unlink(clientPath.c_str());
    throw;
  }
  unlink(serverPath.c_str());
  unlink(clientPath.c_str());

  // The server socket's local address should be the same as the listen
  // address.
  EXPECT_EQ(serverAddr, listenAddr);

  // The client's peer address should always be the same as the server
  // socket's address.
  EXPECT_EQ(clientPeerAddr, serverAddr);

  EXPECT_EQ(serverPeerAddr, clientAddr);
  EXPECT_EQ(serverPeerAddr, acceptAddr);
  EXPECT_EQ(acceptAddr, clientAddr);
}
Ejemplo n.º 22
0
TEST(SocketAddress, IPv4ToStringConversion) {
  // testing addresses *.5.5.5, 5.*.5.5, 5.5.*.5, 5.5.5.*
  SocketAddress addr;
  for (int pos = 0; pos < 4; ++pos) {
    for (int i = 0; i < 256; ++i) {
      int fragments[] = {5,5,5,5};
      fragments[pos] = i;
      std::ostringstream ss;
      ss << fragments[0] << "." << fragments[1] << "."
         << fragments[2] << "." << fragments[3];
      string ipString = ss.str();
      addr.setFromIpPort(ipString, 1234);
      EXPECT_EQ(addr.getAddressStr(), ipString);
    }
  }
}
Ejemplo n.º 23
0
bool Acceptor::canAccept(const SocketAddress& address) {
  if (!connectionCounter_) {
    return true;
  }

  uint64_t maxConnections = connectionCounter_->getMaxConnections();
  if (maxConnections == 0) {
    return true;
  }

  uint64_t currentConnections = connectionCounter_->getNumConnections();
  if (currentConnections < maxConnections) {
    return true;
  }

  if (loadShedConfig_.isWhitelisted(address)) {
    return true;
  }

  // Take care of comparing connection count against max connections across
  // all acceptors. Expensive since a lock must be taken to get the counter.
  auto connectionCountForLoadShedding = getConnectionCountForLoadShedding();
  if (connectionCountForLoadShedding < loadShedConfig_.getMaxConnections()) {
    return true;
  }

  VLOG(4) << address.describe() << " not whitelisted";
  return false;
}
Ejemplo n.º 24
0
void FTPClientSession::sendPORT(const SocketAddress& addr)
{
	std::string arg(addr.host().toString());
	for (std::string::iterator it = arg.begin(); it != arg.end(); ++it)
	{
		if (*it == '.') *it = ',';
	}
	arg += ',';
	Poco::UInt16 port = addr.port();
	arg += NumberFormatter::format(port/256);
	arg += ',';
	arg += NumberFormatter::format(port % 256);
	std::string response;
	int status = sendCommand("PORT", arg, response);
	if (!isPositiveCompletion(status)) throw FTPException("PORT command failed", response, status);
}
Ejemplo n.º 25
0
int SocketImpl::sendTo(const void* buffer, int length, const SocketAddress& address, int flags)
{
	int rc;
	do
	{
		if (_sockfd == POCO_INVALID_SOCKET) throw InvalidSocketException();
#if defined(POCO_VXWORKS)
		rc = ::sendto(_sockfd, (char*) buffer, length, flags, (sockaddr*) address.addr(), address.length());
#else
		rc = ::sendto(_sockfd, reinterpret_cast<const char*>(buffer), length, flags, address.addr(), address.length());
#endif
	}
	while (_blocking && rc < 0 && lastError() == POCO_EINTR);
	if (rc < 0) error();
	return rc;
}
Ejemplo n.º 26
0
nsapi_error_t LWIP::socket_connect(nsapi_socket_t handle, const SocketAddress &address)
{
    struct mbed_lwip_socket *s = (struct mbed_lwip_socket *)handle;
    ip_addr_t ip_addr;

    nsapi_addr_t addr = address.get_addr();
    if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) {
        return NSAPI_ERROR_PARAMETER;
    }

    netconn_set_nonblocking(s->conn, false);
    err_t err = netconn_connect(s->conn, &ip_addr, address.get_port());
    netconn_set_nonblocking(s->conn, true);

    return err_remap(err);
}
Ejemplo n.º 27
0
void UnixDatagramSocketImpl::setMulticastInterface(SocketAddress interfaceAddress)
{
    UnixSocketAddressImpl *addrImpl = dynamic_cast<ios_fc::UnixSocketAddressImpl *>(interfaceAddress.getImpl());
    in_addr_t interface_addr = htonl(addrImpl->getAddress());
    if (setsockopt (socketFd, IPPROTO_IP, IP_MULTICAST_IF, &interface_addr, sizeof(in_addr)) != 0)
        throw Exception("setMulticastInterface: setsockopt failed!\n");
}
Ejemplo n.º 28
0
nsapi_error_t AT_CellularStack::socket_bind(nsapi_socket_t handle, const SocketAddress &addr)
{
    struct CellularSocket *socket = (CellularSocket *)handle;
    if (!socket) {
        return NSAPI_ERROR_DEVICE_ERROR;
    }

    if (addr) {
        return NSAPI_ERROR_UNSUPPORTED;
    }

    _at.lock();

    uint16_t port = addr.get_port();
    if (port != socket->localAddress.get_port()) {
        if (port && (get_socket_index_by_port(port) == -1)) {
            socket->localAddress.set_port(port);
        } else {
            _at.unlock();
            return NSAPI_ERROR_PARAMETER;
        }
    }

    if (!socket->created) {
        create_socket_impl(socket);
    }

    return _at.unlock_return_error();
}
Ejemplo n.º 29
0
int NanostackInterface::socket_bind(void *handle, const SocketAddress &address)
{
    // Validate parameters
    NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
    if (NULL == handle) {
        MBED_ASSERT(false);
        return NSAPI_ERROR_NO_SOCKET;
    }


    nanostack_lock();

    ns_address_t ns_address;
    ns_address.type = ADDRESS_IPV6;
    memset(ns_address.address, 0, sizeof ns_address.address);
    ns_address.identifier = address.get_port();
    int ret = NSAPI_ERROR_DEVICE_ERROR;
    if (0 == ::socket_bind(socket->socket_id, &ns_address)) {
        socket->set_bound();
        ret = 0;
    }

    nanostack_unlock();

    tr_debug("socket_bind(socket=%p) sock_id=%d, ret=%i", socket, socket->socket_id, ret);

    return ret;
}
void NetworkManagerServer::HandlePacketFromNewClient( InputMemoryBitStream& inInputStream, const SocketAddress& inFromAddress )
{
	//read the beginning- is it a hello?
	uint32_t	packetType;
	inInputStream.Read( packetType );
	if(  packetType == kHelloCC )
	{
		//read the name
		string name;
		inInputStream.Read( name );
		ClientProxyPtr newClientProxy = std::make_shared< ClientProxy >( inFromAddress, name, mNewPlayerId++ );
		mAddressToClientMap[ inFromAddress ] = newClientProxy;
		mPlayerIdToClientMap[ newClientProxy->GetPlayerId() ] = newClientProxy;
		
		//tell the server about this client, spawn a cat, etc...
		//if we had a generic message system, this would be a good use for it...
		//instead we'll just tell the server directly
		static_cast< Server* > ( Engine::sInstance.get() )->HandleNewClient( newClientProxy );

		//and welcome the client...
		SendWelcomePacket( newClientProxy );

		//and now init the replication manager with everything we know about!
		for( const auto& pair: mNetworkIdToGameObjectMap )
		{
			newClientProxy->GetReplicationManagerServer().ReplicateCreate( pair.first, pair.second->GetAllStateMask() );
		}
	}
	else
	{
		//bad incoming packet from unknown client- we're under attack!!
		LOG( "Bad incoming packet from unknown client at socket %s", inFromAddress.ToString().c_str() );
	}
}