summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/socket/test_socket.cc
blob: f68b555f43e3e63ffce7fce2667f0299e4912564 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// test_socket.cc
// robert - programme du robot 2005. {{{
//
// Copyright (C) 2005 Dufour J�r�my
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// Contact :
//        Web: %WEB%
//      Email: <dufourj@efrei.fr>
// }}}

#include "server_socket.hh"
#include "address.hh"
#include "socket_text.hh"
#include "data/data_input_file.hh"
#include "data/data_buffer.hh"

#include <iostream>
#include <cstdlib>
#include <stdexcept>
#include <string>
#include <vector>

int
main (int argc, char **argv)
{
    if (argc == 4)
      {
	try
	  {
	    // R�cup�ration des donn�es du fichier
	    DataInputFile df (argv[3]);
	    std::vector <unsigned char> img (319680);
	    df.read (&img[0], 319680);
	    // Ecriture des donn�es du fichier dans le buffer
	    DataBuffer db (&img[0], img.size (), img.size ());
	    // Cr�ation du socket
	    char *h = argv[1];
	    SocketText st (Address (h, atoi (argv[2])));
	    // Envoie des donn�es
	    st << db;
	  }
	catch (const std::runtime_error &r)
	  {
	    std::cerr << argv[0] << ": " << r.what () << std::endl;
	    return 1;
	  }
      }
    else
      {
	std::cerr << "Syntaxe: " << argv[0] << " host port in_file" <<
	    std::endl;
	return 1;
      }
}