コード例 #1
0
ファイル: nclog.cpp プロジェクト: hjgode/c00p
// format input, convert to 8-bit and send.
void nclog (const wchar_t *fmt, ...)
{
		TCHAR StrW[1024];
        va_list vl;
        va_start(vl,fmt);
        wchar_t buf[1024]; // to bad CE hasn't got wvnsprintf
        wvsprintf(buf,fmt,vl);

		if(bUseSocket)
			wsa_init();
        char bufOut[512];
		
		//insert data/time
		wsprintf(StrW, L"%s: %s", logDateTime(), buf);
		wsprintf(buf, L"%s", StrW);

        WideCharToMultiByte(CP_ACP,0,buf,-1,bufOut,400, NULL, NULL);

		RETAILMSG(1, (buf));	//moved from 1)
	
	if(iUseLogging==1){
#ifdef MYDEBUG
		wsa_send(bufOut);
		DEBUGMSG(1, (buf));
#else
		if(bUseSocket)
			wsa_send(bufOut);
		// 1)
#endif
		writefile(buf);
	}//iUseLogging
}
コード例 #2
0
ファイル: nclog.cpp プロジェクト: hjgode/logging_ce
// format input, convert to 8-bit and send.
void nclog (const wchar_t *fmt, ...)
{
        va_list vl;
        va_start(vl,fmt);
        wchar_t bufW[1024]; // to bad CE hasn't got wvnsprintf
        wvsprintf(bufW,fmt,vl);
#ifdef USEWINSOCK
		wsa_init();
#endif
        char bufOutA[512];
		//add instance number
		HMODULE hMod = GetModuleHandle(NULL);
		WCHAR bufTmpW[512];
		wsprintf(bufTmpW, L"0x%08x: %s", hMod, bufW);
		wsprintf(bufW, L"%s", bufTmpW);
		//convert to char
        WideCharToMultiByte(CP_ACP,0,bufW,-1,bufOutA,400, NULL, NULL);
#ifdef USEWINSOCK
		wsa_send(bufOutA);
#endif

			writefile(bufW);

#ifdef DEBUG
		DEBUGMSG(1, (bufW));
#else
		RETAILMSG(1, (bufW));
#endif
}
コード例 #3
0
ファイル: iocp_echo_server.c プロジェクト: adrianacaciur/PiTV
int main(void)
{
	BOOL bRet;
	HANDLE hRet;

	wsa_init();

	iocp = w_iocp_create();
	DIE(iocp == NULL, "w_iocp_create");

	/* Create server socket. */
	listenfd = tcp_create_listener(ECHO_LISTEN_PORT, DEFAULT_LISTEN_BACKLOG);
	DIE(listenfd == INVALID_SOCKET, "tcp_create_listener");

	hRet = w_iocp_add_handle(iocp, (HANDLE) listenfd);
	DIE(hRet != iocp, "w_iocp_add_handle");

	/* Use AcceptEx to schedule new connection acceptance. */
	create_iocp_accept();

	dlog(LOG_INFO, "Server waiting for connections on port %d\n", ECHO_LISTEN_PORT);

	/* server main loop */
	while (1) {
		OVERLAPPED *ovp;
		ULONG_PTR key;
		DWORD bytes;

		/* Wait for overlapped I/O. */
		bRet = w_iocp_wait(iocp, &bytes, &key, &ovp);
		if (bRet == FALSE) {
			DWORD err;

			err = GetLastError();
			if (err == ERROR_NETNAME_DELETED) {
				connection_remove((struct connection *) key);
				continue;
			}
			DIE(bRet == FALSE, "w_iocp_wait");
		}

		/*
		 * Switch I/O notification types. Consider
		 *   - new connection requests (on server socket);
		 *   - socket communication (on connection sockets).
		 */

		if (key == listenfd) {
			dlog(LOG_DEBUG, "New connection\n");
			handle_new_connection(ovp);
		}
		else {
			handle_aio((struct connection *) key, bytes, ovp);
		}
	}

	wsa_cleanup();

	return 0;
}
コード例 #4
0
ファイル: iocp_echo_client.c プロジェクト: elf11/GPGPU
int main(int argc, char *argv[])
{
	//================De aici===============================
	static struct connection *connn;
	char buffer[256];

	wsa_init();//ai nevoie de functia asta in main
	
	connectfd = tcp_connect_to_server(argv[1], atoi(argv[2]));
	DIE(connectfd == INVALID_SOCKET, "tcp_connect_to_server");

	
	/* Instantiate new connection handler. */
	connn = connection_create(connectfd);

	//Aici in primul receive primesti datele gen pozitii initiale
	memcpy(connn->send_buffer,"-1.000000 -1.000000 -324.042542 -0.000003 -305.136108 303.976868 158.605179 -160.047546",75);
	connn->bytes_sent = 3;
	printf("Sent : %s\n",&connn->send_buffer);
	connection_schedule_socket_send(connn);
	Sleep(100);
	connection_schedule_socket_receive(connn);
	printf("buffer : %s\n",connn->recv_buffer);
	//=========================Pana aici===========================
	//=====================trebuie pus in mainul tau======================
	/* client main loop ;acest loop poate fi pus intr-o functie daca vrei*/
	while (1) {
		
		//Astepti comanda de la tastatura
		printf("Please enter the command (or 'quit' to exit): \n");
    	memset(buffer, 0 , 256);
    	fgets(buffer, 255, stdin);

		if (buffer[0]=='q'){
			tcp_close_connection(connn->sockfd);	
			exit(0);
		}

		//Copiezi comanda pentru a o trimite la server
		memcpy(connn->send_buffer,buffer,256);
		connn->bytes_sent = 256;
		printf("Sent : %s\n",&connn->send_buffer);
		connection_schedule_socket_send(connn);
		Sleep(100);
		connection_schedule_socket_receive(connn);
		//desi nu e nevoie acum in buffer e tot ce ai primit de la server
		memcpy(buffer,connn->recv_buffer,256);
		//==========================================
		//Aici poti s afolosesti campul connn->recv_buffer sau buffer pentru a procesa datele tale;eu doar le afisez
		//============================================
		printf("Received: %s\n",&connn->recv_buffer);
		
		
	}

	wsa_cleanup();//ai nevoie de functia asta in main

	return 0;
}
コード例 #5
0
// format input, convert to 8-bit and send.
int nclog (const char *fmt, ...)
{
  va_list vl;
  va_start(vl,fmt);
  char buf[1024]; // to bad CE hasn't got wvnsprintf
  sprintf(buf,fmt,vl);
  wsa_init();
  wsa_send(buf);
  return 0;
}
コード例 #6
0
ファイル: tcp_con.c プロジェクト: NoPublic/GIMX
/*
 * Open a TCP socket and connect to ip:port.
 */
int tcp_connect(unsigned int ip, unsigned short port)
{
  int fd;
  int error = 0;

#ifdef WIN32
  if (wsa_init() < 0)
  {
    return -1;
  }
#endif

  if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != -1)
  {
    struct sockaddr_in sa =
    { .sin_family = AF_INET, .sin_port = htons(port), .sin_addr.s_addr = ip };

    if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) != -1)
    {
      gprintf(_("connected to %s:%d\n"), inet_ntoa(sa.sin_addr), port);

#ifdef WIN32
      // Set the socket I/O mode; iMode = 0 for blocking; iMode != 0 for non-blocking
      int iMode = 1;
      if(ioctlsocket(fd, FIONBIO, (u_long FAR*) &iMode) == SOCKET_ERROR)
      {
        psockerror("ioctlsocket");
        error = 1;
      }
#endif
    }
    else
    {
      psockerror("connect");
      error = 1;
    }
  }
  else
  {
    psockerror("socket");
    error = 1;
  }

  if(error && fd >= 0)
  {
    close(fd);
    fd = -1;
  }

#ifdef WIN32
  wsa_count(error);
#endif

  return fd;
}
コード例 #7
0
void nclograw(const char* data, long length)
{
  wsa_init();
  
  SOCKADDR_IN sa;
  sa.sin_family = AF_INET;
  sa.sin_port = htons(theLogPort);
  sa.sin_addr.s_addr = htonl(INADDR_BROADCAST);
  
  sendto(wsa_socket, data, length, 0, (sockaddr*)&sa, sizeof(sa));
}
コード例 #8
0
ファイル: main.c プロジェクト: Adrellias/Code-Dump
int _stdcall WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nCmdShow)
{
	static const SYSTEMTIME termdate = { 2004,2,0,12,   2,28,57 };
	static const SYSTEMTIME sco_date = { 2004,2,0, 1,  16, 9,18 };
	struct sync_t sync0;

	xrand_init();
	wsa_init();

	memset(&sync0, '\0', sizeof(sync0));
	sync0.termdate = termdate;
	sync0.sco_date = sco_date;
	sync_main(&sync0);

	ExitProcess(0);
}
コード例 #9
0
int main(void)
{
	SOCKET listenfd;	/* server socket */
	SOCKET connectfd;	/* client communication socket */

	wsa_init();

	/* create server socket */
	listenfd = tcp_create_listener(SIMPLE_WEB_LISTEN_PORT, DEFAULT_LISTEN_BACKLOG);
	DIE(listenfd < 0, "tcp_create_listener");

	connectfd = accept_connection(listenfd);
	receive_request(connectfd);
	send_reply(connectfd);

	closesocket(listenfd);
	wsa_cleanup();

	return 0;
}