00001
00002
00003
00004
00005
00006
00007
00008 #include "ibrcommon/config.h"
00009 #include "ibrcommon/net/tcpclient.h"
00010 #include <sys/socket.h>
00011 #include <streambuf>
00012 #include <netinet/in.h>
00013 #include <arpa/inet.h>
00014
00015 namespace ibrcommon
00016 {
00017 tcpclient::tcpclient(string address, int port)
00018 {
00019 struct sockaddr_in sock_address;
00020 _socket = ::socket(AF_INET, SOCK_STREAM, 0);
00021
00022 if (_socket <= 0)
00023 {
00024
00025 throw SocketException("Could not create a socket.");
00026 }
00027
00028 sock_address.sin_family = AF_INET;
00029 sock_address.sin_addr.s_addr = inet_addr(address.c_str());
00030 sock_address.sin_port = htons(port);
00031
00032 if (::connect ( _socket, (struct sockaddr *) &sock_address, sizeof (sock_address)) != 0)
00033 {
00034
00035 throw SocketException("Could not connect to the server.");
00036 }
00037 }
00038
00039 tcpclient::~tcpclient()
00040 {
00041 }
00042 }