blob: 3573740786772b080e4f8a369d30930d5aac6b23 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001// Copyright (C) 1999-2005 Open Source Telecom Corporation.
2// Copyright (C) 2009 Leandro Melo de Sales <leandroal@gmail.com>
3//
4// This example demonstrates the operation of a client DCCP,
5// where it connects to a server through the address and port,
6// after you connect to the server it writes data to the socket.
7//
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 2 of the License, or
11// (at your option) any later version.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21//
22// As a special exception to the GNU General Public License, permission is
23// granted for additional uses of the text contained in its release
24// of Common C++.
25//
26// The exception is that, if you link the Common C++ library with other
27// files to produce an executable, this does not by itself cause the
28// resulting executable to be covered by the GNU General Public License.
29// Your use of that executable is in no way restricted on account of
30// linking the Common C++ library code into it.
31//
32// This exception does not however invalidate any other reasons why
33// the executable file might be covered by the GNU General Public License.
34//
35// This exception applies only to the code released under the
36// name Common C++. If you copy code from other releases into a copy of
37// Common C++, as the General Public License permits, the exception does
38// not apply to the code that you add in this way. To avoid misleading
39// anyone as to the status of such modified files, you must delete
40// this exception notice from them.
41//
42// If you write modifications of your own for Common C++, it is your choice
43// whether to permit this exception to apply to your modifications.
44// If you do not wish that, delete this exception notice.
45
46#include <cc++/socket.h>
47#include <iostream>
48#include <cstdlib>
49
50#ifdef CCXX_NAMESPACES
51using namespace std;
52using namespace ost;
53#endif
54
55class MyDCCPSocket : public DCCPSocket
56{
57public:
58 ssize_t myWriteData(const char *buf);
59 ssize_t myReadLine(char* buf);
60 void myBufferSize(unsigned size);
61};
62
63void MyDCCPSocket::myBufferSize(unsigned size){
64 this->bufferSize(size);
65}
66
67//This method writes data on socket
68ssize_t MyDCCPSocket::myWriteData(const char *buf){
69 return this-> writeData(buf,strlen(buf));
70}
71//This method read data on socket
72ssize_t MyDCCPSocket::myReadLine(char* buf){
73 return this->readLine(buf, 200);
74}
75
76int main(int argc, char *argv[])
77{
78 //port and address of the server to connect
79 tpport_t port = 7000;
80 IPV4Host addr= "127.0.0.1";
81
82 //Startup of client DCCP
83 MyDCCPSocket client;
84 cout << "Try connect server in " << addr << ":" << port << endl;
85
86 //client connects to the server
87 client.connect(addr,port);
88
89 //message to be written to the socket
90 char mss[] = "Hello Server\n";
91
92 //call the method of writing data
93 client.myWriteData(mss);
94
95 //call the method of reading data
96 char buffer[200];
97 client.myReadLine(buffer);
98
99 //printing the data read
100 cout << buffer << endl;
101
102 return 0;
103}