1 /*************************************************************************/
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996,1997 */
6 /* All Rights Reserved. */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
32 /*************************************************************************/
33 /* Author : Alan Black (with Richard Tobin) */
34 /* Date : December 1996 */
35 /*-----------------------------------------------------------------------*/
37 /* Low level client functions, separated from the other scoket functions */
38 /* so things that link with these don't need the whole system */
40 /*=======================================================================*/
44 #include <sys/types.h>
48 #include "EST_socket.h"
50 #include "festivalP.h"
52 static EST_Regex ipnum("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+");
54 int festival_socket_client(const char *host,int port)
56 // Return an FD to a remote server
57 struct sockaddr_in serv_addr;
58 struct hostent *serverhost;
62 if (!socket_initialise())
66 fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
70 int n = socket_error();
71 cerr << "socket: socket failed (" << n << ")\n";
74 memset(&serv_addr, 0, sizeof(serv_addr));
76 if (shost.matches(ipnum))
77 serv_addr.sin_addr.s_addr = inet_addr(host);
80 serverhost = gethostbyname(host);
81 if (serverhost == (struct hostent *)0)
83 cerr << "socket: gethostbyname failed" << endl;
86 memmove(&serv_addr.sin_addr,serverhost->h_addr, serverhost->h_length);
88 serv_addr.sin_family = AF_INET;
89 serv_addr.sin_port = htons(port);
91 if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != 0)
93 cerr << "socket: connect failed" << endl;