TCP/IP网络编程与Web开发全解析
1. TCP服务器 - 客户端基础程序
以下是一个简单的TCP客户端程序示例:
printf("4 : connected OK to\n"); printf("-------------------------------------------------------\n"); printf("Server hostname=%s PORT=%d\n", SERVER_HOST, SERVER_PORT); printf("-------------------------------------------------------\n"); printf("========= init done ==========\n"); } int main() { int n; char line[MAX], ans[MAX]; client_init(); printf("******** processing loop *********\n"); while (1){ printf("input a line : "); bzero(line, MAX); // zero out line[ ] fgets(line, MAX, stdin); // get a line from stdin line[strlen(line)-1] = 0; // kill \n at end if (line[0]==0) //