Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F-stack Client not Connecting to F-stack Server #474

Open
SUDOsarvesh opened this issue Jan 3, 2020 · 0 comments
Open

F-stack Client not Connecting to F-stack Server #474

SUDOsarvesh opened this issue Jan 3, 2020 · 0 comments

Comments

@SUDOsarvesh
Copy link

SUDOsarvesh commented Jan 3, 2020

Hey F-stack Geeks,
I am New to F-stack. I am trying to make tcp connection via F-stack over dpdk(19.08). The example given in F-stack package creates server but when i am trying to connect that port from same or another pc It is not responding anything.Still in netstat it is showing that server is listening but i am not able to connect from my client application. I tried client application with n without (eg Winshock Client app) F-stack but nothing good.
Here is my f-stack client code.
#include <stdio.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
#include <assert.h>

#include "ff_config.h"
#include "ff_api.h"
#include "ff_epoll.h"

#define MAX_EVENTS 512

struct epoll_event ev;
struct epoll_event events[MAX_EVENTS];

int epfd;
int sockfd;

char html[] =
"HTTP/1.1 200 OK\r\n"
"Server: F-Stack\r\n"
"Date: Sat, 25 Feb 2017 09:26:33 GMT\r\n"
"Content-Type: text/html\r\n"
"Content-Length: 438\r\n"
"Last-Modified: Tue, 21 Feb 2017 09:44:03 GMT\r\n"
"Connection: keep-alive\r\n"
"Accept-Ranges: bytes\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"<title>Welcome to F-Stack!</title>\r\n"
"<style>\r\n"
" body { \r\n"
" width: 35em;\r\n"
" margin: 0 auto; \r\n"
" font-family: Tahoma, Verdana, Arial, sans-serif;\r\n"
" }\r\n"
"</style>\r\n"
"\r\n"
"\r\n"
"

Welcome to F-Stack!

\r\n"
"\r\n"
"

For online documentation and support please refer to\r\n"
"<a href="http://F-Stack.org/\">F-Stack.org.
\r\n"
"\r\n"
"

Thank you for using F-Stack.

\r\n"
"\r\n"
"";
struct sockaddr_in my_addr;
int loop(void arg)
{
/
Wait for events to happen */

int nevents = ff_epoll_wait(epfd,  events, MAX_EVENTS, 0);
int i;

for (i = 0; i < nevents; ++i) {
    /* Handle new connect */
    if (events[i].data.fd == sockfd) {
        while (1) {
            int nclientfd = ff_accept(sockfd, (struct linux_sockaddr *)&my_addr, sizeof(my_addr));
            if (nclientfd < 0) {
                break;
            }

            /* Add to event list */
            ev.data.fd = nclientfd;
            ev.events  = EPOLLIN;
            if (ff_epoll_ctl(epfd, EPOLL_CTL_ADD, nclientfd, &ev) != 0) {
                printf("ff_epoll_ctl failed:%d, %s\n", errno,
                    strerror(errno));
                break;
            }
        }
    } else { 
        if (events[i].events & EPOLLERR ) {
            /* Simply close socket */
            ff_epoll_ctl(epfd, EPOLL_CTL_DEL,  events[i].data.fd, NULL);
            ff_close(events[i].data.fd);
        } else if (events[i].events & EPOLLIN) {
            char buf[256];
            size_t readlen = ff_read( events[i].data.fd, buf, sizeof(buf));
            if(readlen > 0) {
                ff_write( events[i].data.fd, html, sizeof(html) - 1);
            } else {
                ff_epoll_ctl(epfd, EPOLL_CTL_DEL,  events[i].data.fd, NULL);
                ff_close( events[i].data.fd);
            }
        } else {
            printf("unknown event: %8.8X\n", events[i].events);
        }
    }
}

}

int main(int argc, char * argv[])
{
ff_init(argc, argv);

sockfd = ff_socket(AF_INET, SOCK_STREAM, 0);
printf("sockfd:%d\n", sockfd);
if (sockfd < 0) {
    printf("ff_socket failed\n");
    exit(1);
}

int on = 1;
ff_ioctl(sockfd, FIONBIO, &on);


bzero(&my_addr, sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(15231);
my_addr.sin_addr.s_addr = inet_addr("127.0.0.1");

int ret = ff_bind(sockfd, (struct linux_sockaddr *)&my_addr, sizeof(my_addr));
if (ret < 0) {
    printf("ff_bind failed\n");
    exit(1);
}

ret = (ff_connect(sockfd, (struct linux_sockaddr *)&my_addr, sizeof(my_addr)) == -1);  //ff_connect
if (ret < 0) {
    printf("ff_listen failed\n");
    exit(1);
}

assert((epfd = ff_epoll_create(0)) > 0);
ev.data.fd = sockfd;
ev.events = EPOLLIN;
ff_epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &ev);
ff_run(loop, NULL);
return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant