Exemple #1
0
int main(int argc, char *argv[])
{
  ConnectionManager connection;
  SOCKET connect_socket = connection.CreateClientConnection();

  #pragma region WYSYLANIE

  #define DEFAULT_BUFLEN 512

  int recvbuflen = DEFAULT_BUFLEN;

  char *sendbuf = new char[DEFAULT_BUFLEN];
  char recvbuf[DEFAULT_BUFLEN];

  int result = 0;

  do {
  printf("Wiadomosc do wyslania: \n");
  scanf("%s", sendbuf);
  //printf("Wiadomosc jaka wysle: %s\n", sendbuf);

  if (strcmp(sendbuf, "quit") == 0) break;
  // Send an initial buffer
  result = send(connect_socket, sendbuf, static_cast<int>(strlen(sendbuf)), 0);
  if (result == SOCKET_ERROR) {
  printf("send failed: %d\n", WSAGetLastError());
  closesocket(connect_socket);
  WSACleanup();
  //
  getch();
  //
  return 1;
  }
  } while (true);

  #pragma endregion blok odpowiedzialny za komunikacje z serwerem

  connection.ShutdownConnection(connect_socket);

	printf("Client exit.\n");
	getch();
	return 0;
}
Exemple #2
0
int main(int argc, char *argv[])
{
  ConnectionManager connection;
  SOCKET listen_socket = connection.CreateServerConnection();
  SOCKET client_socket;
  
  ProcessesAndThreadsManager process_manager;

  while (client_socket = connection.AcceptingConnection(listen_socket)) {

    // in there should be process_manager.SetPathToProcess function
    char *sciezka = new char[256];
    strcpy(sciezka, "F:\\dropbox\\myftp\\MyFTP - ClientsManager\\ClientsManager\\debug\\ClientsManager");
    strcat(sciezka, " ");
    // copy socket handle to argument list of new process
    char str_to_socket[10];
    itoa(client_socket, str_to_socket, 10);
    strcat(sciezka, str_to_socket);
    printf("Sciezka do procesu tuz przed wyslaniem:\n%s\n", sciezka);
    USES_CONVERSION;
    TCHAR* dziecko = A2T(sciezka);
    process_manager.path_to_process_ = dziecko;

    process_manager.CreateNewProcess();

  }

  process_manager.WaitForProcessToEnd();
  process_manager.CloseHandles();
  printf("Client disconnect.\n");

  connection.ShutdownConnection(client_socket);
  closesocket(listen_socket);

	printf("Server exit.\n");
	return 0;
}