sendoob.cc revision 475e9be4
1475e9be4SShuo Chen#include "InetAddress.h" 2475e9be4SShuo Chen#include "Socket.h" 3475e9be4SShuo Chen#include <string.h> 4475e9be4SShuo Chen 5475e9be4SShuo Chenint main(int argc, char* argv[]) 6475e9be4SShuo Chen{ 7475e9be4SShuo Chen if (argc < 3) 8475e9be4SShuo Chen { 9475e9be4SShuo Chen printf("Usage:\n %s hostname port\n", argv[0]); 10475e9be4SShuo Chen return 0; 11475e9be4SShuo Chen } 12475e9be4SShuo Chen 13475e9be4SShuo Chen int port = atoi(argv[2]); 14475e9be4SShuo Chen InetAddress addr(port); 15475e9be4SShuo Chen const char* hostname = argv[1]; 16475e9be4SShuo Chen if (InetAddress::resolve(hostname, &addr)) 17475e9be4SShuo Chen { 18475e9be4SShuo Chen Socket sock(Socket::createTCP()); 19475e9be4SShuo Chen if (sock.connect(addr) == 0) 20475e9be4SShuo Chen { 21475e9be4SShuo Chen const char* buf = "hello"; 22475e9be4SShuo Chen ssize_t nw = ::send(sock.fd(), buf, strlen(buf), MSG_OOB); 23475e9be4SShuo Chen printf("sent %zd bytes\n", nw); 24475e9be4SShuo Chen getchar(); 25475e9be4SShuo Chen } 26475e9be4SShuo Chen else 27475e9be4SShuo Chen { 28475e9be4SShuo Chen perror("connect"); 29475e9be4SShuo Chen } 30475e9be4SShuo Chen } 31475e9be4SShuo Chen} 32