| 130 | |
| 131 | |
| 132 | void setup(){ |
| 133 | serv.sin_family = AF_INET; |
| 134 | serv.sin_port = htons(8096); //Define the port at which the server will listen for connections. |
| 135 | serv.sin_addr.s_addr = INADDR_ANY; |
| 136 | fd = socket(AF_INET, SOCK_STREAM, 0); //This will create a new socket and also return the identifier of the socket into fd. |
| 137 | // To handle errors, you can add an if condition that checks whether fd is greater than 0. If it isn't, prompt an error |
| 138 | while(1){ |
| 139 | int t = bind(fd, (struct sockaddr *)&serv, sizeof(serv)); //assigns the address specified by serv to the socket |
| 140 | if(t == 0){ |
| 141 | break; |
| 142 | } |
| 143 | printf("Problem with setting up the port\n"); |
| 144 | exit(0); |
| 145 | } |
| 146 | listen(fd,5); //Listen for client connections. Maximum 5 connections will be permitted. |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | int main(){ |
| 151 | char message[16] = ""; //This array will store the messages that are sent by the server |