Thread: Windows network programming from a console program

  1. #1
    Registered User
    Join Date
    Oct 2021
    Posts
    21

    Windows network programming from a console program

    I am looking for the simplest code that does a client and server side socket connection in visual studio with c that does NOT use the windows.h call.

    I am trying to write something in console and windows based visual studio c. ANY USEFUL suggestions?

    I know there is no socket.h in visual studio and I'd rather not use windows.h

    Thanks,

    ME

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Windows Sockets 2 - Win32 apps | Microsoft Learn

    Perhaps you need to read this first.
    Beej's Guide to Network Programming

    Then read the rest of Beej's guide, which includes a working client/server demo.
    Beej's Guide to Network Programming

    > use the windows.h call.
    You don't call header files.

    Just including the header file called "windows.h" does NOT make your program a GUI program.
    Console programs can call functions defined in windows.h just fine.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2021
    Posts
    21
    Code:
    // simp_calendar.cpp : Defines the entry point for the console application.
    // Written Visual Studio 2005 C.
    // Starting days are ONE day later from the previous year unless a leap year then they are TWO.
    
    
    #include <stdio.h>
    // January 1st, 2023 was a SUNDAY.
    // January 1st, 1598 was a SUNDAY.
    // 1600 was a leap year.
    
    
    
    
    int global_year_printing=1598;
    int global_month_printing=0;
    int day_start_count=1; // Starting count day 1-7 of the week start should NEVER be more than 7.
    
    
    // prints the title days of the week
    int print_titles_of_week()	{
    	printf("\n\tSun\tMon\tTue\tWed\tThu\tFri\tSat\n");
    return 0;
    }
    
    
    // prints the days of each month
    int print_days_of_month(int month)	{
    	int end_day=0;
    	if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12) {
    		end_day=31;
    	}
    	if (month==4 || month==6 || month==9 || month==11) {
    		end_day=30;
    	}
    	if (month==2) {
    		end_day=28;
    	}
    	if (month==2 && global_year_printing%4==0) {
    		end_day=29;
    	}
    	for (int x=1; x<=day_start_count-1; x=x+1) {printf("\t"); }
    	for (int n=1; n<end_day+1; n=n+1)		{		
    		printf("\t%d",n);	
    		day_start_count=day_start_count+1;		
    		if (day_start_count==8)	{ printf("\n");	day_start_count=1; }
    	}
    printf("\n");
    return 0;
    }
    
    
    int print_month(int monthsyear)		{
    	printf("\n\t%d", global_year_printing);
    	if (monthsyear==1)	{ printf("\tJANUARY\n");	}	
    	if (monthsyear==2)	{ printf("\tFEBRUARY\n");	}
    	if (monthsyear==3)	{ printf("\tMARCH\n");		}	
    	if (monthsyear==4)	{ printf("\tAPRIL\n");		}
    	if (monthsyear==5)	{ printf("\tMAY\n");		}	
    	if (monthsyear==6)	{ printf("\tJUNE\n");		}
    	if (monthsyear==7)	{ printf("\tJULY\n");		}	
    	if (monthsyear==8)	{ printf("\tAUGUST\n");		}
    	if (monthsyear==9)	{ printf("\tSEPTEMBER\n");	}	
    	if (monthsyear==10) { printf("\tOCTOBER\n");	}
    	if (monthsyear==11) { printf("\tNOVEMBER\n");	}	
    	if (monthsyear==12) { printf("\tDECEMBER\n");	}
    return 0;
    }
    
    
    int get_year ()	{
    	printf("Enter the year to print after 1600: ");
    	scanf("%d", &global_year_printing);
    	if (global_year_printing > 1598) { day_start_count=global_year_printing-1598+1; }
    	if (global_year_printing > 1600) { 
    		day_start_count=day_start_count+((global_year_printing-1600)/4);
    		day_start_count=day_start_count+1; 	
    	}
    	day_start_count=day_start_count%7;
    	if (day_start_count==0)	{day_start_count=1;} 
    	return 0;
    }
    
    
    int main()	{
    	get_year();
    	for (int months_of_year_loop=1; months_of_year_loop<13; months_of_year_loop=months_of_year_loop+1 )		{
    		print_month(months_of_year_loop);
    		print_titles_of_week();
    		print_days_of_month(months_of_year_loop);		
    	}
    	//printf("\ntest:%d\n", 5/4);
    return 0;
    }

  4. #4
    Registered User
    Join Date
    Oct 2021
    Posts
    21
    That UNIX platform is not what I am looking for. I found some code from Microsoft.
    I posted a calendar code set for other C coders.

    Microsoft wrote something about NETW.

    Complete Winsock Client Code - Win32 apps | Microsoft Learn

    Complete Winsock Server Code - Win32 apps | Microsoft Learn
    Last edited by cprogramnoob; 09-03-2023 at 12:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. windows network programming noob question
    By mramazing in forum Networking/Device Communication
    Replies: 6
    Last Post: 01-27-2009, 04:20 PM
  2. Network Programming in C for Windows
    By m.mixon in forum C Programming
    Replies: 7
    Last Post: 06-19-2006, 08:27 PM
  3. Replies: 4
    Last Post: 07-12-2002, 01:52 PM
  4. Question about console and windows programming
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 06-22-2002, 05:46 AM
  5. Newbie Question -> Is Console programming different from Windows ?
    By Unregistered in forum Windows Programming
    Replies: 6
    Last Post: 04-16-2002, 08:50 PM

Tags for this Thread