コード例 #1
0
ファイル: 2048.c プロジェクト: Librazy/2o48.hackable.c
/// \brief  Print welcome message and input the size of the board
/// \return void
void welcome(){
    clear();
    char mesg[]=":2o48_Network";
    getmaxyx(stdscr,row,col);
    mvprintw(row/2,(col-strlen(mesg))/2,mesg);
    int ver=c_version();
    char verstr[100];
    char infostr[100]="Press N to connect to server,S to be a server";
    sprintf(verstr,"version %X",ver);
    mvprintw(row/2+1,(col-strlen(verstr))/2,verstr);
    mvprintw(row/2+2,(col-strlen(infostr))/2,infostr);
    mvprintw(row-3,0,"Welcome to :2048 by Librazy\n");
    printw("Enter a number<=9 that you want the board be:");
    int inpN=4+'0';
    while(1){
        inpN=getch();
        if((inpN==3)||(inpN==KEY_F(1)))c_forceQuit();
        if(inpN>'0'&&inpN<='9')break;
        if(inpN=='n'||inpN=='N'){
            mvprintw(row-3,0,"Networking mode now,enter ip you want to connect\n");clrtoeol();move(row-2,0);echo();
            char ipstr[130]={0};
            while(scanw("%127s",ipstr)!=1){mvprintw(row-3,0,"Networking mode now,enter ip you want to connect!\n");clrtoeol();move(row-2,0);}
            noecho();
            SClient = dyad_newStream();
            printw(ipstr);
            printw(",Enter a number<=9 that you want the board be:");
            while(1){
                inpN=getch();
                if(inpN>'0'&&inpN<='9'){
                    N=(char)(inpN-'0');printw("%d",N);refresh();break;
                }
            }
            pthread_create (&TInfo, &AThread, t_Info, NULL);
            pthread_mutex_lock(&MNetC);
            connecting=true;
            isnetworking=true;
            dyad_addListener(SClient, DYAD_EVENT_DATA, n_Data, NULL);
            dyad_addListener(SClient, DYAD_EVENT_ERROR, g_Error, NULL);
            dyad_connect(SClient,ipstr, 2048);
            return;
        }
        if(inpN=='s'||inpN=='S'){
            move(row-3,0);clrtoeol();move(row-2,0);clrtoeol();
            SServ = dyad_newStream();
            pthread_create (&TInfo, &AThread, t_Info, NULL);
            pthread_mutex_lock(&MNetC);
            connecting=true;
            isnetworking=true;
            dyad_addListener(SServ, DYAD_EVENT_ERROR, g_Error, NULL);
            dyad_addListener(SServ, DYAD_EVENT_ACCEPT, s_Accept, NULL);
            dyad_listenEx(SServ, "0.0.0.0",2048,1);//Force IPv4
			mvprintw(row-3,0,"Serving mode now,listening port 2048\n"); refresh();
            return;
        }
    }
    N=(char)(inpN-'0');
    printw("%d\nThe board will be %d.Press any key and rock on!",N,N);
    getch();
    pthread_create (&TInfo, &AThread, t_Info, NULL);
}
コード例 #2
0
ファイル: dyad.c プロジェクト: shanfl/dyad
int dyad_listen(dyad_Stream *stream, int port) {
  return dyad_listenEx(stream, NULL, port, 511);
}
コード例 #3
0
ファイル: dyad.hpp プロジェクト: cia48621793/dyad
		int listen(const char *host, int port, int backlog = INT_MAX) {
			return dyad_listenEx(m_wrap, host, port, backlog);
		}