示例#1
0
	void Socket::Bind(u_short port, IPAddress address)
	{
		sockaddr_in service;
		service.sin_family = AF_INET;
		service.sin_port = htons(port);
		service.sin_addr.s_addr = htonl(address.Address());

		if (0 != bind(hSocket, (const SOCKADDR *)&service, sizeof(SOCKADDR))) {
			throw Win32Exception("bind");
		}
	}
示例#2
0
	AsyncResultPtr Socket::BeginConnect(u_short port, IPAddress address, AsyncCallback callback, const ObjectPtr &asyncState)
	{
		AsyncResultPtr asyncResult(this, Nothing, asyncState, Nothing, callback);
		asyncResult->AddRef();

		sockaddr_in name;
		name.sin_family = AF_INET;
		name.sin_port = htons(port);
		name.sin_addr.s_addr = htonl(address.Address());

		SocketProvider &msp = SocketProvider::GetSingleton();
		if (!msp.ConnectEx(hSocket, (SOCKADDR *)&name, sizeof(SOCKADDR), 0, 0, 0, asyncResult.operator ->())
			&& WSAGetLastError() != WSA_IO_PENDING)
		{
			asyncResult->Release();
			throw Win32Exception("ConnectEx");
		}

		return asyncResult;
	}