我有一个客户端连接到服务器(TCP连接).在服务器崩溃(我断开连接)的情况下,我的客户端需要连接到另一台服务器,以便继续服务.但是当第一台服务器回来时,我需要再次将客户端重新连接到它.在第一台服务器崩溃后,我能够将我的客户端连接到备份服务器,但是我将客户端重新连接到第一台服务器时出现问题.我做了一个create_newconnect()重新连接到服务器的功能,但它不起作用(这就是为什么我不在代码中调用它)我试图尽可能地简化我的程序,所以它不会很大这是客户端
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <signal.h>
#include <string.h>
#include <arpa/inet.h>
#include <time.h>
#define SIZE sizeof(struct sockaddr_in)
struct sockaddr_in server;
void tcp_protocol();//execute client tcp protocol
void server_check();
void tcp();
void create_newconnect();
int main (int argc, char *argv[])
{
int portno;
//Test for correct number of arguments
if (argc != 3)
{
fprintf(stderr, "Usage: %s Port# IP Address \n", argv[0]);
exit(1);
}
portno = atoi(argv[1]);//convert port # to int
server.sin_family = …Run Code Online (Sandbox Code Playgroud)