static int client_socket_receive( comm_channel_t *channel, char *buf, int len )
{
    tcp_connection_t *tc = tcp_get_connection( channel );
    int res;

    if( !tc )
    {
        return( -1 );
    }

    if( !tc->connected )
    {
        res = client_socket_connect( tc );
    }

    if( tc->connected )
    {
        res = socket_read( tc->fd, buf, len );

        if( res == -1 )
        {
            close_connection( tc );
        }
    }

    return( res );
}
Example #2
0
//initializes the client communication
int initialize_client(Gui *gui){
  char *server = "127.0.0.1";
  int port = 5993;
  gui->sockfd = client_socket_connect(server, port);

  

  return 1;
}
static int client_socket_init( tcp_connection_t *tc, char *addr, int port )
{
    struct sockaddr_in *clientinfo = &tc->clientinfo;
    uint32_t caddr;

    tc->connected = 0;
    tc->fd = -1;

    if( inet_pton( AF_INET, addr, &caddr ) <= 0 )
    {
        fprintf( stderr, "ERROR in %s %d: inet_pton\n",
            __FILE__, __LINE__ );
        return( -1 );
    }

    clientinfo->sin_family      = AF_INET;
    clientinfo->sin_addr.s_addr = caddr;
    clientinfo->sin_port        = htons( (short) port );

    client_socket_connect( tc );
    return( 0 );
}