int main(int argc, char const *argv[]) { if(argc < 2) { printf("Usage: ./client <port>\n"); exit(1); } pthread_t pid; int port = atoi(argv[1]); int sfd = tcpsocket_connect(port); if(sfd < 0) { perror("tcpclient_connect() "); exit(2); } char buf[BUFSIZE]; int id; ticket_t tkt; recv(sfd, buf, BUFSIZE, 0); if(atoi(buf) == -1) { printf("Housefull Oops !!\n"); close(sfd); } else { printf("%s\n", buf); memset(buf, 0, BUFSIZE); scanf("%d", &id); sprintf(buf, "%d", id); send(sfd, buf, strlen(buf), 0); memset(buf, 0, BUFSIZE); recv(sfd, buf, BUFSIZE, 0); printf("Ticket ID: %s", buf); sleep(1); // wait for final confirmation memset(buf, 0, BUFSIZE); recv(sfd, buf, BUFSIZE, 0); if(atoi(buf) == -1) { printf("Housefull Your Ticket has been Cancelled!!\n"); close(sfd); exit(3); } else { printf("You entered %s\n", buf); pthread_create(&pid, NULL, &runner, (void *) &sfd); pthread_join(pid, NULL); } } return 0; }
int TcpSocketUtil::Connect(const char* url, size_t timeout) { if (NULL == url) { return INVLD_ARGUMENT; } fd_ = tcpsocket_connect(url, timeout); if (fd_ < 0) { return CONNECT_FAILED; } tcpsocket_set_recvbuff(fd_, recv_buf_.buff_size * 2); tcpsocket_set_sendbuff(fd_, send_buf_.buff_size * 2); socket_state_ = NET_CONNECTED; url_ = url; return NORMAL; }