memcached_return memcached_server_add_unix_socket_with_weight(memcached_st *ptr, const char *filename, uint32_t weight) { if (!filename) return MEMCACHED_FAILURE; return server_add(ptr, filename, 0, weight, MEMCACHED_CONNECTION_UNIX_SOCKET); }
memcached_return memcached_server_add_with_weight(memcached_st *ptr, const char *hostname, unsigned int port, uint32_t weight) { if (!port) port= MEMCACHED_DEFAULT_PORT; if (!hostname) hostname= "localhost"; return server_add(ptr, hostname, port, weight, MEMCACHED_CONNECTION_TCP); }
/* server add <servertag> <RFC1459|Timestamp|P10|User|BitlBee> <hostname> <service|portnumber> <nickname|none> <localname> <password|none> <identity> */ bool cfg_conf_server_add(struct cfg_state *cmd, char *args) { int fields = countfields(args); char tag[25], type[10], hostname[24], service[24], nick[24], local[24], pass[24], identity[24]; enum srv_types typ = SRV_BITLBEE; /* Add requires 8 variables */ if ( fields != 8 || !copyfield(args, 1, tag, sizeof(tag)) || !copyfield(args, 2, type, sizeof(type)) || !copyfield(args, 3, hostname, sizeof(hostname)) || !copyfield(args, 4, service, sizeof(service)) || !copyfield(args, 5, nick, sizeof(nick)) || !copyfield(args, 6, local, sizeof(local)) || !copyfield(args, 7, pass, sizeof(pass)) || !copyfield(args, 8, identity, sizeof(identity))) { sock_printf(cmd->sock, "400 The command is: server add <servertag> <RFC1459|Timestamp|P10|User|BitlBee> <hostname> <service|portnumber> <nickname|none> <localname> <password> <identity>\n"); return false; } if ( strcasecmp(type, "rfc1459" ) == 0) typ = SRV_RFC1459; else if (strcasecmp(type, "timestamp" ) == 0) typ = SRV_TS; else if (strcasecmp(type, "bitlbee" ) == 0) typ = SRV_BITLBEE; else if (strcasecmp(type, "user" ) == 0) typ = SRV_USER; else { sock_printf(cmd->sock, "400 '%s' is an unsupported server type\n", type); return false; } if (server_find_tag(tag)) { sock_printf(cmd->sock, "400 Server '%s' already exists\n", tag); return false; } if (server_add(tag, typ, hostname, service, strcasecmp(nick, "none") == 0 ? NULL : nick, local, strcasecmp(pass, "none") == 0 ? NULL : pass, identity, g_conf->service_description)) { sock_printf(cmd->sock, "200 Added server %s\n", tag); return true; } sock_printf(cmd->sock, "400 Server addition failed\n"); return false; }
int conf_add(char *parameter, char *value) { if (strcasecmp(parameter, "channel") == 0) { channel_add(value); } else if (strcasecmp(parameter, "server") == 0) { char host[128], port[6], *p, ipv6=0; if ((p = strtok(value, " \r\n")) == NULL) return 0; strncpy(host, p, sizeof(host)); if ((p = strtok(NULL, " \r\n")) == NULL) return 0; strncpy(port, p, sizeof(port)); p = strtok(NULL, " \r\n"); if (p) if (strcasecmp(p, "ipv6") == 0) ipv6 = 1; #ifndef IPV6 if (ipv6 == 1) { log(LOG_WARNING, "Unable to add IPv6 server '%s'! " "You don't have IPv6 support enabled.", host); return 0; } #endif server_add(host, (u_short)atoi(port), ipv6); } else { log(LOG_ERROR, "add: Unknown parameter \"%s\"", parameter); return -1; } return 0; }
int main() { std::cout << "서버 초기화 시작" << std::endl; Poco::Net::SocketAddress server_add(PORT); Poco::Net::ServerSocket server_sock(server_add); std::cout << "서버 초기화 완료. 클라이언트 접속 대기 중..." << std::endl; while (true) { Poco::Net::StreamSocket ss = server_sock.acceptConnection(); try { char buffer[256] = { 0, }; int n = ss.receiveBytes(buffer, sizeof(buffer)); std::cout << "클라이언트에서 받은 메시지: " << buffer << std::endl; while (n > 0) { char szSendMessage[256] = { 0, }; sprintf_s(szSendMessage, 128 - 1, "Re:%s", buffer); int nMsgLen = strnlen_s(szSendMessage, 256 - 1); ss.sendBytes(szSendMessage, nMsgLen); n = ss.receiveBytes(buffer, sizeof(buffer)); std::cout << "클라이언트에서 받은 메시지: " << buffer << std::endl; } std::cout << "클라이언트와 연결이 끊어졌습니다" << std::endl; } catch (Poco::Exception& exc) { std::cerr << "EchoServer: " << exc.displayText() << std::endl; } } getchar(); return 0; }