LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-30-2010, 03:42 AM   #1
thirumalesh
Member
 
Registered: Sep 2007
Posts: 54

Rep: Reputation: 15
Persistent and Full Duplex TCP connection


Hi,

In my client application i have to connect to a payment gateway server
which should be persistent and full-duplex connection....

Can anybody guide me in this.....

Thanks In advance........
 
Old 06-30-2010, 09:21 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
You can use 'ETHTOOL_OPTS="speed 100 duplex full autoneg off"' in your network config files - /etc/sysconfig/network-scripts/ifcfg-ethX

hth
 
Old 06-30-2010, 02:49 PM   #3
jork
LQ Newbie
 
Registered: Jun 2010
Location: beweth
Distribution: Ubuntu, RHEL, Monta Vista, QNX
Posts: 16

Rep: Reputation: 0
Quote:
Originally Posted by kbp View Post
You can use 'ETHTOOL_OPTS="speed 100 duplex full autoneg off"' in your network config files - /etc/sysconfig/network-scripts/ifcfg-ethX

hth
This is for the ethernet link config. Normally the ethernet links are by default configured 100/1G nowadays and will be full duplex also unless otherwise configured.

Can you elaborate a little bit more on your requirement once again. What do you mean by a full duplex persistent TCP connection?

-jork
 
Old 07-01-2010, 02:34 AM   #4
thirumalesh
Member
 
Registered: Sep 2007
Posts: 54

Original Poster
Rep: Reputation: 15
Actually I am asking about a design to write a module,
which will create a full-duplex connection with paymeny gateway
i.e which can send requests and receive responses from the server..
and also server can send some messages it should respond to those.....

This should happen in a persistent connection

Last edited by thirumalesh; 07-01-2010 at 02:35 AM. Reason: some thing to add
 
Old 07-01-2010, 02:42 AM   #5
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Maybe this should be in the coding forum not networking...
 
Old 07-01-2010, 04:17 AM   #6
jork
LQ Newbie
 
Registered: Jun 2010
Location: beweth
Distribution: Ubuntu, RHEL, Monta Vista, QNX
Posts: 16

Rep: Reputation: 0
Quote:
Originally Posted by kbp View Post
Maybe this should be in the coding forum not networking...
What your requirement is a very common tcp use case. Just put the socket in non blocking and use poll or select() on the socket for finding the events on the socket and process them based on your requirement.

tcp connections natively are full-duplex.

find here is a sample program i've written for accomplishing your requirement. you may use it as an infra and build on it. Feel free to use it if you find its useful.

Code:
/* Joshith */

#include <stdio.h>
#include <sys/select.h>

#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/time.h>
#include <asm/ioctls.h>

main ()

{

int fd =-1;
unsigned long arg = 1;
struct sockaddr_in s_addr;
int retval = 0;
char data[2048];

int fl =0;
int err = 0;
int len = sizeof(err);
struct timeval tv = {0,0};
int i=0;
fd_set rd_set, wr_set, ex_set;

fd = socket (AF_INET, SOCK_STREAM, 0);

if (fd < 0) {
        printf ("socket() err: %d, errno: %d\n", fd, errno);
        return 0;
}

printf("socket opened fd:%d\n", fd);
if(ioctl(fd, FIONBIO, &arg) == -1) {
        printf ("err putting non-blocking. arg: %lu, errno: %d\n", arg, errno);
        close (fd);
        return -1;
}

    s_addr.sin_family = AF_INET;
    s_addr.sin_addr.s_addr = htonl(421075218);
    s_addr.sin_port = htons(333);

retval = connect(fd, (struct sockaddr*)&s_addr, sizeof(s_addr));

printf("Connecting.. \n");

if(retval <0) {
        printf("connect err: retval:%d, errno: %d\n", retval, errno);
        if(errno == EWOULDBLOCK)
                printf("EWOULLDBOCK\n");
        else if(errno == EINPROGRESS)
                printf("EINPROBGRESS\n");
        else
                { printf ("Fatal err!!\n");
                  close (fd);
                  return -1;
                }

} else {

printf("success: retval: %d\n", retval);

}


while (1) {

FD_ZERO(&rd_set);
FD_ZERO(&wr_set);
FD_ZERO(&ex_set);

FD_SET(fd, &rd_set);
FD_SET(fd, &wr_set);
FD_SET(fd, &ex_set);

        retval = select(2048, &rd_set, &wr_set, &ex_set, NULL);

        printf("timeval sec:%d usec %lu \n", tv.tv_sec, tv.tv_usec);
        tv.tv_sec = 10; tv.tv_usec=0;
        if(retval <0) {
                printf( "select err: %d\n", retval);
                close (fd);
                return -1;
        } else if(retval > 0) {
                printf("Select pop-up \n");
             if(FD_ISSET(fd, &rd_set)) {
                printf("rd_set: i=%d retval: %d\n calling recv()\n",i, retval);
                if((retval = recv(fd, data, 2048, 0)) < 0) {
                        if(errno == ECONNRESET)
                                printf("Conn errno: ECONNRESET, retval %d \n", retval);
                        else if(errno == ECONNREFUSED)
                                printf("Conn errno: ECONNREFUSED, retval %d \n", retval);
                        else
                                printf("ERR: errno:%d, retval %d\n", errno, retval);
                } else {
                        printf("RECV retval:%d, data:%s \n", retval, data);

                        // DO your recvieved data processing here
                }
             }
             if(FD_ISSET(fd, &wr_set)) {
                printf("wr_set: i=%d \n calling getsockopt()\n",i);
                if((retval = getsockopt (fd, SOL_SOCKET, SO_ERROR,
                                          (char*)&err, &len) == -1) || (err != 0)) {
                        if(err == ECONNRESET)
                                printf("sockopt ret -1, err: ECONNRESET, %d\n", err);
                        else
                                printf("sockopt ret -1, err: %d\n", err);

                        // YOu can Send() data from here.
                }else {
                        printf("sockopt: establ ret %d, err: %d\n", retval, err);
                }
                }
             if(FD_ISSET(fd, &ex_set)) {
                printf("ex_set: i=%d \n",i);

                }
        } else {
                printf("timeout \n");

        }

                printf("errno:%d\n*********\n\n", errno);
                errno = 0;
        if(i<10)
           i++;
        else
           break;
}

close (fd);
return 0;

}
ps: contact me for the royalty info for my code :-)

-jork
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't change from half-duplex to full-duplex on a gigabit nic brgsousa Linux - Software 4 05-29-2010 11:03 AM
half-duplex and full-duplex vs. cable. stf92 Linux - Hardware 6 03-01-2010 07:42 PM
Persistent open TCP connection to dubious hosting site. cyent Linux - Security 3 04-17-2008 03:14 PM
full duplex chazzwozzer Linux - Networking 1 02-07-2005 02:11 PM
OSS and Full duplex !!!! OneManArmy Debian 1 06-25-2004 09:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration