client and server programs


 
Thread Tools Search this Thread
Top Forums Programming client and server programs
# 1  
Old 03-01-2007
client and server programs

Hello,

Looking at the asio.sourceforge.net library, I found a tutorial to develop simple client and server programs. Below I am pasting the client and the server. On my Fedora Core 4, I can compile the two programs(client is 'a' and server is 'daytime', but I have no idea on how to test them...
./a
returns
Usage: client <host>
while
./daytime
returns
Permission denied

What should I do to make the two programs talk to each other? I am sure it is pretty basic here but I cannot seem to figure it out. I am posting on this forum because it looks to me that this is more a unix question than an asio one.
thanks in advance
Regards,


SERVER
Code:
 
#include <ctime>
#include <iostream>
#include <string>
#include <boost/asio.hpp>

using boost::asio::ip::tcp;

std::string make_daytime_string()
{
  using namespace std; // For time_t, time and ctime;
  time_t now = time(0);
  return ctime(&now);
}

int main()
{
  try
  {
    boost::asio::io_service io_service;

    tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), 13));

    for (;;)
    {
      tcp::socket socket(io_service);
      acceptor.accept(socket);

      std::string message = make_daytime_string();

      boost::asio::write(socket, boost::asio::buffer(message),
          boost::asio::transfer_all(), boost::asio::ignore_error());
    }
  }
  catch (std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }

  return 0;
}


CLIENT
Code:
#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>

using boost::asio::ip::tcp;

int main(int argc, char* argv[])
{
  try
  {
    if (argc != 2)
    {
      std::cerr << "Usage: client <host>" << std::endl;
      return 1;
    }
    
    boost::asio::io_service io_service;

    tcp::resolver resolver(io_service);
    tcp::resolver::query query(argv[1], "daytime");
    tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
    tcp::resolver::iterator end;

    tcp::socket socket(io_service);
    boost::asio::error error = boost::asio::error::host_not_found;
    while (error && endpoint_iterator != end)
    {
      socket.close();
      socket.connect(*endpoint_iterator++, boost::asio::assign_error(error));
    }
    if (error)
      throw error;

    for (;;)
    {
      boost::array<char, 128> buf;
      boost::asio::error error;

      size_t len = socket.read_some(
          boost::asio::buffer(buf), boost::asio::assign_error(error));

      if (error == boost::asio::error::eof)
        break; // Connection closed cleanly by peer.
      else if (error)
        throw error; // Some other error.

      std::cout.write(buf.data(), len);
    }
  }
  catch (std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }

  return 0;
}

# 2  
Old 03-02-2007
The error with the server is likely that there are no permissions to run the file. Check and make sure that the file has the x bit set. For the client, you need to specify the name of the server to connect to.
# 3  
Old 03-02-2007
I changed the permission for server with
chmod 777 daytime
but
./a daytime
still returns
Host not found (authoritative).
What would be the right syntax to add the <host>?
Thanks!
# 4  
Old 03-02-2007
actually, when I run from root
./daytime
the process starts running and
ps -A
returns
7268 pts/1 00:00:00 daytime

well, I am still confused on what's exactly is going on... and what I should do to use that server from my client

Last edited by JCR; 03-02-2007 at 07:20 AM..
# 5  
Old 03-03-2007
Learn raw sockets first http://beej.us/guide/bgnet/
# 6  
Old 03-03-2007
That's a pretty good tutorial.Thank you. Light has not yet come on my specific problem but I agree that there is no shortcut here.
# 7  
Old 02-17-2009
May be this is late, but just in case someone else gets into the same problem in the future:

this most most likely because your account does not have permissions to execute some of the run-time shared libraries needed for this application or may be you do not have permissions to run them from the within the folder in which they reside.

To find out what libraries you need to run the app:
Code:
$ ldd <your app>

And then copy all the shared libraries into your apps folder and change their permission so you can execute them.

then make sure, when compiling and linking the app, that you include the app's folder as one of the run-time libraries search folders.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between inbuilt suid programs and user defined root suid programs under bash shell?

Hey guys, Suppose i run passwd via bash shell. It is a suid program, which temporarily runs as root(owner) and modifies the user entries. However, when i write a C file and give 4755 permission and root ownership to the 'a.out' file , it doesn't run as root in bash shell. I verified this by... (2 Replies)
Discussion started by: syncmaster
2 Replies

2. Shell Programming and Scripting

Sftp script for dev server to client server

hi, i am new to unix, cuold u send some sftp acripts to send files to dev server to clint server, (1 Reply)
Discussion started by: Koti.annam
1 Replies

3. UNIX for Advanced & Expert Users

client / server pipe?

Hi Can anyone tell me the simplest way to get two bash scripts to communicate with each other when running on two different servers? Is it possible to use a named pipe or something similar? Thanks in advance Steady (2 Replies)
Discussion started by: steadyonabix
2 Replies

4. UNIX for Dummies Questions & Answers

Client server C

Hello, Please, is there on unix.com the source code of a client C and server C: as shown in following figure: File:InternetSocketBasicDiagram zhtw.png - Wikipedia, the free encyclopedia Thank you so much for help (1 Reply)
Discussion started by: chercheur857
1 Replies

5. Programming

Client Server C

Hello, Please I would create a client and a server in C that communicate frequently. The client sends "hello message" to the server, the server waits a few minutes and sends a "hello message" to the client, the client sends again "hello server ".. etc up to 15 minutes Can you guide me... (3 Replies)
Discussion started by: chercheur857
3 Replies

6. Windows & DOS: Issues & Discussions

Office server => laptop =>client server ...a lengthy and laborious ftp procedure

Hi All, I need your expertise in finding a way to solve my problem.Please excuse if this is not the right forum to ask this question and guide me to the correct forum,if possible. I am a DBA and on a daily basis i have to ftp huge dump files from my company server to my laptop and then... (3 Replies)
Discussion started by: kunwar
3 Replies

7. UNIX for Dummies Questions & Answers

Are programs like sys_open( ) ,sys_read( ) et al examples of system level programs ?

Are the programs written on schedulers ,thread library , process management, memory management, et al called systems programs ? How are they different from the programs that implement functions like open() , printf() , scanf() , read() .. they have a prefix sys_open, sys_close, sys_read etc , right... (1 Reply)
Discussion started by: vishwamitra
1 Replies

8. Programming

Client/Server Socket Application - Preventing Client from quitting on server crash

Problem - Linux Client/Server Socket Application: Preventing Client from quitting on server crash Hi, I am writing a Linux socket Server and Client using TCP protocol on Ubuntu 9.04 x64. I am having problem trying to implement a scenario where the client should keep running even when the... (2 Replies)
Discussion started by: varun.nagpaal
2 Replies

9. Shell Programming and Scripting

Client-server

Hi, I have installed the vmware server on my debian os and has several clients connected to it. Is there any script that enable the server to restart the client automatically?? Can anyone help. Thanks in advance (3 Replies)
Discussion started by: kanexxx
3 Replies

10. UNIX for Dummies Questions & Answers

client/server

Hi, yes i belong to that duummies group of people so here is the question that i need someone to explain it to me and posiblly to answere it to me in a plain english. This is the question: Describe the concept of “client-server” software. Discuss what each side of the equation... (2 Replies)
Discussion started by: bole
2 Replies
Login or Register to Ask a Question