void Client(char *filename)
{
    int clientSocketDescriptor;
    int connectResult;
    FILE *rdfile;

    rdfile = fopen(filename, "r");
    if (rdfile == NULL)
    {
        puts ("Error while opening file.");
        return;
    }
    clientSocketDescriptor = StartClient("tcp");
    connectResult = ClientConnect(clientSocketDescriptor, "127.0.0.1", 6660);
    if (connectResult == -1)
    {
        return;
    }
    if (SendFileName(clientSocketDescriptor, filename) == -1)
    {
        return;
    }
    if (SendFileSize(clientSocketDescriptor, rdfile) == -1)
    {
        return;
    }
    ClientProcess(clientSocketDescriptor, rdfile);
    ShutdownSocket(clientSocketDescriptor);
    CloseSocket(clientSocketDescriptor);
    fclose(rdfile);

    return;
}
Exemple #2
0
int main( int argc, char const **argv )
{
   NetworkSystem net;

   if (!net.init()) {
      return 1;
   }

   // Do rest of program here
   char const *my_host_name = AllocLocalHostName();
   printf( "Host name: %s\n", my_host_name );

   PrintAddressesForHost( my_host_name, "1234" );

   if (argc > 2) {
      char const *host_name = argv[1];
      char const *msg = argv[2];
      // Start a client
      StartClient( host_name, "1234", msg );
   } else {
      StartHost( my_host_name, "1234" );
   }

   net.deinit();

   printf( "Press any key to continue..." );
   _getch();
   return 0;
}
Exemple #3
0
	void Application::Start()
	{
		SetTitle("Ur: GOTY Edition!");
		
		RN::Kernel::GetSharedInstance()->SetMaxFPS(60);
//		RN::Window::GetSharedInstance()->ActivateConfiguration(RN::Window::GetSharedInstance()->GetMainScreen()->GetConfigurations()->GetLastObject()->Downcast<RN::WindowConfiguration>(), RN::Window::Mask::Fullscreen);
		
		RN::MessageCenter::GetSharedInstance()->AddObserver(kRNInputEventMessage, [this](RN::Message *message) {
			
			RN::Event *event = message->Downcast<RN::Event>();
			if(event->GetType() == RN::Event::Type::KeyDown)
			{
				char key = event->GetCharacter();
				switch(key)
				{
					case '0':
						StartServer();
						break;
						
					case '1':
						StartClient();
						break;
				}
			}
			
		}, this);
	}
Exemple #4
0
ClientOpt *login(char *user_name) {
	
	FILE *network_config;
	char *server_ip, *server_port, *client_port;
	if((network_config = fopen("network.config", "r")) == NULL) {
		printf("can not open network.config file");
		return NULL;
	}
	else {
		server_ip = fgetstr(network_config);
		server_port = fgetstr(network_config);
		client_port = fgetstr(network_config);
	}

	printf("server_ip:%s, server_port:%s, client_port:%s", server_ip, server_port, client_port);

	ClientOpt *copt = (ClientOpt *)calloc(1, sizeof(ClientOpt));
	copt->buffer_len = 1024;
	copt->remote_port = atoi(server_port);
	strcpy(copt->server_name, server_ip);
	copt->SocketProc = receivePackage;
	copt->user_name = user_name;
	copt->local_port = client_port;


	HANDLE * h = StartClient(copt);

	Login(copt);

	return copt;
}
Exemple #5
0
bool MsgClient::Start( void )
{
	if ( ! _httpcaller.Start() ) {
		OUT_ERROR( NULL, 0, NULL, "start http caller failed" ) ;
		return false ;
	}
	return StartClient( "0.0.0.0", 0, 3 ) ;
}
Exemple #6
0
bool MsgClient::Start( void )
{
	// 初始化两个HTTP对象
	if ( ! _httpCall.Start() ) {
		OUT_ERROR( NULL, 0, NULL, "start http caller failed") ;
		return false ;
	}
	return StartClient( "0.0.0.0", 0, 4 ) ;
}
Exemple #7
0
netClient::netClient(hnDisplay *display, char *serverAddress):
	m_display(display), 
	m_packet(NULL),
	m_done(false)
{
	m_serverAddress = new sockaddr_in;
	m_display->SetClient(this);
	StartClient(serverAddress);
}
// Tests IPv6 client/server.
TEST_F(SocketTest, IPv6) {
    ASSERT_TRUE(StartServer());
    ASSERT_TRUE(StartClient("::1"));

    EXPECT_TRUE(SendString(client_.get(), "foo"));
    EXPECT_EQ("foo", ReceiveString(server_.get()));

    EXPECT_TRUE(SendString(server_.get(), "bar"));
    EXPECT_EQ("bar", ReceiveString(client_.get()));
}
// Tests sending packets client -> server, then server -> client.
TEST_F(SocketTest, SendAndReceive) {
    ASSERT_TRUE(StartServer());
    ASSERT_TRUE(StartClient());

    EXPECT_TRUE(SendString(client_.get(), "foo"));
    EXPECT_EQ("foo", ReceiveString(server_.get()));

    EXPECT_TRUE(SendString(server_.get(), "bar baz"));
    EXPECT_EQ("bar baz", ReceiveString(client_.get()));
}
Exemple #10
0
AJ_Status AJ_StartClientByInterface(AJ_BusAttachment* bus,
                                    const char* daemonName,
                                    uint32_t timeout,
                                    uint8_t connected,
                                    const char** interfaces,
                                    uint32_t* sessionId,
                                    char* serviceName,
                                    const AJ_SessionOpts* opts)
{
    return StartClient(bus, daemonName, timeout, connected, NULL, 0, interfaces, sessionId, serviceName, opts);
}
Exemple #11
0
AJ_Status AJ_StartClient(AJ_BusAttachment* bus,
                         const char* daemonName,
                         uint32_t timeout,
                         uint8_t connected,
                         const char* name,
                         uint16_t port,
                         uint32_t* sessionId,
                         const AJ_SessionOpts* opts)
{
    return StartClient(bus, daemonName, timeout, connected, name, port, NULL, sessionId, NULL, opts);
}
Exemple #12
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

	client = new ClientModel;

	connect(client, SIGNAL(SendMessageToMainForm(QString)), this, SLOT(UpdateLog(QString)));
	connect(ui->startButton, SIGNAL(clicked()), this, SLOT(StartClient()));
}
Exemple #13
0
bool PasClient::Start( void )
{
	// 启动车辆静态数据信息
	_busloader.Start() ;

	// 这里需要UDP做数据通道
	if ( ! StartUDP( "0.0.0.0", _port , 15 ) ) {
		printf( "start udp server failed" ) ;
		OUT_ERROR( NULL, 0, NULL, "start udp server failed" ) ;
		return false ;
	}
	// 这里需要TCP做控制通道
	return StartClient( "0.0.0.0", 0, 3 ) ;
}
Exemple #14
0
__dead void
ManageSession (struct display *d)
{
    pid_t	pid = 0;
    greet_user_rtn	greet_stat;

    Debug ("ManageSession %s\n", d->name);
    (void)XSetIOErrorHandler(IOErrorHandler);
    (void)XSetErrorHandler(ErrorHandler);
    setproctitle("%s", d->name);


    if (d->autoLogin == NULL || d->autoLogin[0] == '\0') {
        /* Load system default Resources */
        LoadXloginResources (d);
        greet_stat = GreetUser(d, &verify, &greet);
    } else
        greet_stat = AutoLogin(d, &verify, &greet);

    if (greet_stat == Greet_Success) {
	clientPid = 0;
	(void) signal (SIGTERM, catchTerm);
	/*
	 * Start the clients, changing uid/groups
	 *	   setting up environment and running the session
	 */
	if (StartClient (&verify, d, &clientPid, greet.name)) {
	  Debug ("Client Started\n");
	  /* Wait for session to end, */
	  pid = waitpid(clientPid, NULL, 0);
	  if (pid <= 0 && abortSession) {
	    /*
	     * when terminating the session, nuke
	     * the child and then run the reset script
	     */
	    AbortClient (clientPid);
	  }
	} else {
	  LogError ("session start failed\n");
	}
    }
    /*
     * run system-wide reset file
     */
    if (d->windowPath != NULL)
        login_fbtab(d->windowPath, 0, 0);
    Debug ("Source reset program %s\n", d->reset);
    source (verify.systemEnviron, d->reset);
    SessionExit (d, OBEYSESS_DISPLAY, TRUE);
}
// Tests receive overflow (the UDP packet is larger than the receive buffer).
TEST_F(SocketTest, ReceiveOverflow) {
    ASSERT_TRUE(StartServer());
    ASSERT_TRUE(StartClient());

    EXPECT_TRUE(SendString(client_.get(), "1234567890"));

    // This behaves differently on different systems; some give us a truncated UDP packet, others
    // will error out and not return anything at all.
    std::string rx_string = ReceiveString(server_.get(), 5);

    // If we didn't get an error then the packet should have been truncated.
    if (rx_string != kReceiveStringError) {
        EXPECT_EQ("12345", rx_string);
    }
}
TEST_F(SSFFixtureTest, ConnectToUnknownHost) {
  // Init timer (if client hangs)
  boost::system::error_code timer_ec;
  auto timer_callback = [this](const boost::system::error_code& ec) {
    EXPECT_NE(0, ec.value()) << "Timer should be canceled. Client is hanging";
    if (!ec) {
      SendNotification(false);
    }
  };
  StartTimer(std::chrono::seconds(5), timer_callback, timer_ec);

  auto client_callback = [this](ssf::Status status) {
    switch (status) {
      case ssf::Status::kEndpointNotResolvable:
      case ssf::Status::kServerUnreachable:
        SSF_LOG("test", critical, "Network initialization failed");
        SendNotification(true);
        break;
      case ssf::Status::kServerNotSupported:
        SSF_LOG("test", critical, "Transport initialization failed");
        SendNotification(false);
        break;
      case ssf::Status::kConnected:
        SendNotification(false);
        break;
      case ssf::Status::kDisconnected:
        SSF_LOG("test", info, "client: disconnected");
        break;
      case ssf::Status::kRunning:
        SendNotification(false);
        break;
      default:
        break;
    }
  };

  boost::system::error_code run_ec;
  StartClient("16000", client_callback, run_ec);
  ASSERT_EQ(0, run_ec.value()) << "Could not start client";

  // Wait client action
  WaitNotification();

  EXPECT_TRUE(IsNotificationSuccess()) << "Stop failed";

  StopClient();
  StopTimer();
}
// Tests sending and receiving large packets.
TEST_F(SocketTest, LargePackets) {
    std::string message(512, '\0');

    ASSERT_TRUE(StartServer());
    ASSERT_TRUE(StartClient());

    // Run through the test a few times.
    for (int i = 0; i < 10; ++i) {
        // Use a different message each iteration to prevent false positives.
        for (size_t j = 0; j < message.length(); ++j) {
            message[j] = static_cast<char>(i + j);
        }

        EXPECT_TRUE(SendString(client_.get(), message));
        EXPECT_EQ(message, ReceiveString(server_.get(), message.length()));
    }
}
// Tests multiple clients sending to the same server.
TEST_F(SocketTest, MultipleClients) {
    ASSERT_TRUE(StartServer());
    ASSERT_TRUE(StartClient());
    ASSERT_TRUE(StartClient2());

    EXPECT_TRUE(SendString(client_.get(), "client"));
    EXPECT_TRUE(SendString(client2_.get(), "client2"));

    // Receive the packets and send a response for each (note that packets may be received
    // out-of-order).
    for (int i = 0; i < 2; ++i) {
        std::string received = ReceiveString(server_.get());
        EXPECT_TRUE(SendString(server_.get(), received + " response"));
    }

    EXPECT_EQ("client response", ReceiveString(client_.get()));
    EXPECT_EQ("client2 response", ReceiveString(client2_.get()));
}
HRESULT RemoteDebuggerProxy::Start()
{
    if ( mSessionGuid != GUID_NULL )
        return S_OK;

    HRESULT     hr = S_OK;
    GUID        sessionGuid = { 0 };
    wchar_t     sessionGuidStr[GUID_LENGTH + 1] = L"";
    int         ret = 0;

    hr = CoCreateGuid( &sessionGuid );
    if ( FAILED( hr ) )
        return hr;

    ret = StringFromGUID2( sessionGuid, sessionGuidStr, _countof( sessionGuidStr ) );
    _ASSERT( ret > 0 );
    if ( ret == 0 )
        return E_FAIL;

    mSessionGuid = sessionGuid;

    hr = StartAgent( sessionGuidStr );
    if ( FAILED( hr ) )
        return hr;

    hr = StartServer( sessionGuidStr );
    if ( FAILED( hr ) )
        return hr;

    SetRemoteEventCallback( this );
    hr = StartClient( sessionGuidStr, sessionGuid, mhContext );
    SetRemoteEventCallback( NULL );
    if ( FAILED( hr ) )
    {
        StopServer();
        return hr;
    }

    return S_OK;
}
Exemple #20
0
bool CVechileMgr::Start( void )
{
	if ( ! _send_thread.init( 1 , (void*) THREAD_SEND, this ) ) {
		printf( "init send thread failed\n" ) ;
		return false ;
	}

	_vechile_inited  = true ;

	_send_thread.start() ;

	_bench.Start() ;

	// 是否为UDP模式
	if ( _connect_mode & UDP_MODE ) {
		if ( ! StartUDP( _server_ip.c_str(), _server_port, _thread_num ) ) {
			printf( "start udp client failed\n" ) ;
			return false ;
		}
	}
	// 启动处理线程
	return StartClient( _server_ip.c_str(), _server_port , _thread_num ) ;
}
Exemple #21
0
//-----------------------------------------------------------------------------
// Thread is started. This is the first function called from thread's context.
// Returns: error number
int TestThread::OnStart() {
    int ret;

    _times = new Times(_count);
    _timer->Start(1000, this);

    // Start a client or a server
    if(_mode == 's') { // Server
        printf("Server mode\n");
        ret = StartServer();
        if(ret)
            return ret;
    } else if(_mode == 'c') { // Client
        printf("Client mode\n");
        ret = StartClient();
        if(ret)
            return ret;
    } else {
        printf("Unknown mode: %c\n", _mode);
        return -1;
    }

    return 0;
}
void socketTransfertClient::MasterDisconnect()
{
	WSACleanup();
	StartClient(m_peerIp, m_peerPort);
}
Exemple #23
0
void
ManageSession (struct display *d)
{
    static int		pid = 0;
    Display		*dpy;
    greet_user_rtn	greet_stat; 
    static GreetUserProc greet_user_proc = NULL;
#ifndef GREET_USER_STATIC
    void		*greet_lib_handle;
#endif

    Debug ("ManageSession %s\n", d->name);
    (void)XSetIOErrorHandler(IOErrorHandler);
    (void)XSetErrorHandler(ErrorHandler);
#ifndef HAS_SETPROCTITLE
    SetTitle(d->name, (char *) 0);
#else
    setproctitle("%s", d->name);
#endif
    /*
     * Load system default Resources
     */
    LoadXloginResources (d);

#ifdef GREET_USER_STATIC
    greet_user_proc = GreetUser;
#else
    Debug("ManageSession: loading greeter library %s\n", greeterLib);
    greet_lib_handle = dlopen(greeterLib, RTLD_NOW);
    if (greet_lib_handle != NULL)
	greet_user_proc = (GreetUserProc)dlsym(greet_lib_handle, "GreetUser");
    if (greet_user_proc == NULL)
	{
	LogError("%s while loading %s\n", dlerror(), greeterLib);
	exit(UNMANAGE_DISPLAY);
	}
#endif

    /* tell the possibly dynamically loaded greeter function
     * what data structure formats to expect.
     * These version numbers are registered with The Open Group. */
    verify.version = 1;
    greet.version = 1;
    greet_stat = (*greet_user_proc)(d, &dpy, &verify, &greet, &dlfuncs);

    if (greet_stat == Greet_Success)
    {
	clientPid = 0;
	if (!Setjmp (abortSession)) {
	    (void) Signal (SIGTERM, catchTerm);
	    /*
	     * Start the clients, changing uid/groups
	     *	   setting up environment and running the session
	     */
	    if (StartClient (&verify, d, &clientPid, greet.name, greet.password)) {
		Debug ("Client Started\n");

#ifndef GREET_USER_STATIC
                /* Save memory; close library */
                dlclose(greet_lib_handle);
#endif
 
		/*
		 * Wait for session to end,
		 */
		for (;;) {
		    if (d->pingInterval)
		    {
			if (!Setjmp (pingTime))
			{
			    (void) Signal (SIGALRM, catchAlrm);
			    (void) alarm (d->pingInterval * 60);
			    pid = wait ((waitType *) 0);
			    (void) alarm (0);
			}
			else
			{
			    (void) alarm (0);
			    if (!PingServer (d, (Display *) NULL))
				SessionPingFailed (d);
			}
		    }
		    else
		    {
			pid = wait ((waitType *) 0);
		    }
		    if (pid == clientPid)
			break;
		}
	    } else {
		LogError ("session start failed\n");
	    }
	} else {
	    /*
	     * when terminating the session, nuke
	     * the child and then run the reset script
	     */
	    AbortClient (clientPid);
	}
    }
    /*
     * run system-wide reset file
     */
    Debug ("Source reset program %s\n", d->reset);
    source (verify.systemEnviron, d->reset);
    SessionExit (d, OBEYSESS_DISPLAY, TRUE);
}
Exemple #24
0
bool MsgClient::Start(void)
{
	return StartClient("0.0.0.0", 0, 1);
}
Exemple #25
0
void CGameControllerEXP::RestartClient(int ID)
{
	StartClient(ID);
	GameServer()->SendChatTarget(ID, "Game restarted.");
}
TEST_F(SSFFixtureTest, CloseWhileConnecting) {
  // Init server
  int server_port = 15000;
  boost::asio::ip::tcp::acceptor server(get_io_service());
  InitTCPServer(server, server_port);

  // Init timer (if client hangs)
  boost::system::error_code timer_ec;
  auto timer_callback = [this](const boost::system::error_code& ec) {
    EXPECT_NE(0, ec.value()) << "Timer should be canceled. Client is hanging";
    if (!ec) {
      SendNotification(false);
    }
  };
  StartTimer(std::chrono::seconds(20), timer_callback, timer_ec);
  ASSERT_EQ(0, timer_ec.value()) << "Could not start timer";

  // Init client
  auto client_callback = [this](ssf::Status status) {
    switch (status) {
      case ssf::Status::kEndpointNotResolvable:
      case ssf::Status::kServerUnreachable:
        SSF_LOG("test", critical, "Network initialization failed");
        SendNotification(true);
        break;
      case ssf::Status::kServerNotSupported:
        SSF_LOG("test", critical, "Transport initialization failed");
        SendNotification(true);
        break;
      case ssf::Status::kConnected:
        SendNotification(true);
        break;
      case ssf::Status::kDisconnected:
        SSF_LOG("test", info, "client: disconnected");
        break;
      case ssf::Status::kRunning:
        SendNotification(false);
        break;
      default:
        break;
    }
  };
  boost::system::error_code run_ec;
  StartClient(std::to_string(server_port), client_callback, run_ec);
  ASSERT_EQ(0, run_ec.value());

  // Wait new server connection
  boost::asio::ip::tcp::socket socket(get_io_service());
  server.async_accept(socket, [this](const boost::system::error_code& ec) {
    EXPECT_EQ(0, ec.value()) << "Accept connection in error";
    // Stop client while connecting
    StopClient();
  });

  // Wait client action
  WaitNotification();

  EXPECT_TRUE(IsNotificationSuccess()) << "Stop failed";

  StopTimer();
  boost::system::error_code close_ec;
  socket.close(close_ec);
  server.close(close_ec);
}
Exemple #27
0
void ManageSession(struct display *d)
{
	static int pid = 0;
	Display *dpy;
	greet_user_rtn greet_stat;
#ifdef WITH_CONSOLE_KIT
	char *ck_session_cookie = NULL;
#endif

	WDMDebug("ManageSession %s\n", d->name);
	(void)XSetIOErrorHandler(IOErrorHandler);
	(void)XSetErrorHandler(ErrorHandler);
#ifndef HAS_SETPROCTITLE
	SetTitle(d->name, (char *)0);
#else
	setproctitle("%s", d->name);
#endif
	/*
	 * Load system default Resources
	 */
	LoadXloginResources(d);

	verify.version = 1;
	greet.version = 1;
	greet_stat = GreetUser(d, &dpy, &verify, &greet);

	if (greet_stat == Greet_Success) {
		clientPid = 0;
		if (!Setjmp(abortSession)) {
			(void)Signal(SIGTERM, catchTerm);
			/*
			 * Start the clients, changing uid/groups
			 *     setting up environment and running the session
			 */
#ifdef WITH_CONSOLE_KIT
			ck_session_cookie = open_ck_session(getpwnam(greet.name), d);
#endif
			if (StartClient(&verify, d, &clientPid, greet.name, greet.password
#ifdef WITH_CONSOLE_KIT
							, ck_session_cookie
#endif
				)) {
				WDMDebug("Client Started\n");

				/*
				 * Wait for session to end,
				 */
				for (;;) {
					if (d->pingInterval) {
						if (!Setjmp(pingTime)) {
							(void)Signal(SIGALRM, catchAlrm);
							(void)alarm(d->pingInterval * 60);
							pid = wait((waitType *) 0);
							(void)alarm(0);
						} else {
							(void)alarm(0);
							if (!PingServer(d, (Display *) NULL))
								SessionPingFailed(d);
						}
					} else {
						pid = wait((waitType *) 0);
					}
					if (pid == clientPid)
						break;
				}
			} else {
				WDMError("session start failed\n");
			}
		} else {
			/*
			 * when terminating the session, nuke
			 * the child and then run the reset script
			 */
			AbortClient(clientPid);
		}
	}
#ifdef WITH_CONSOLE_KIT
	if (ck_session_cookie != NULL) {
		close_ck_session(ck_session_cookie);
		free(ck_session_cookie);
	}
#endif

	/*
	 * run system-wide reset file
	 */
	WDMDebug("Source reset program %s\n", d->reset);
	source(verify.systemEnviron, d->reset);
	SessionExit(d, OBEYSESS_DISPLAY, TRUE);
}
 virtual void SetUp() {
   StartServer();
   StartClient();
 }
Exemple #29
0
bool TcpClient::Start(void) {
	return StartClient(_client_user._ip.c_str(), _client_user._port, _thread_num);
}