“Situ Electro Instruments Pvt. Ltd.” <seto@vsnl.com> wrote in message
news:95tuvs$5d5$1@inn.qnx.com…
Hello,
it depends on what do you mean under “dual-up connected line”. if you
mean
running tcp/ip over serial line with ppp then i guess changes should be
minimal.
look at “Socket Programming Guide” shipped with tcp/ip development kit for
qnx4.
actually, you need the following steps:
-
start socket dayemon. don’t remember how is it in 4.x tcp/ip but if you
use tcp/ip 5b
just run “#> /usr/ucb/Tcpip MyHostName &”.
-
establishe ppp connection between two computers over direct link or
probably
modem connection. if you use dirrect connection just start pppd on both
ends. if you
use modem connection then you should first dial from one host to another
with qtalk
or any other communication program and start pppd next.
note: afair it wasn’t so easy to configure propertly ppp connection between
qnx4 and
windoze and guess same situation might be with qnx4-qnx4 connectivity. i
don’t remember
right now all tips so feel free to ask if you will find some troubles.
- from your receiver host program (let to call it server) you should open
tcp socket,
assign needed address info, bring it into listen state and in circle accept
all [or selected]
incomming connections and transmit all needed data. kind of :
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define LISTEN_PORT 1234 /* this is a tcp port you wish to listen on
*/
struct sockaddr_in sa;
int sock,data_sock;
static const char smsg[] = “server reply message”;
static char rmsg[100];
/* create tcp socket */
sock = socket(AF_INET,SOCK_STREAM,0);
/* bind address info to created socket /
memset(&sa,0,sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = INADDR_ANY; / receive requests from any
ip address /
sa.sin_port = htons(LISTEN_PORT)
bind(sock,(struct sockaddr)&sa,sizeof(sa));
/* bring your socket into “listen” state */
listen(sock,5);
for (; {
/*
wait for incomming connection and accept it
accept returns file descriptor (socket) which should be used for
futher operations during this connection
*/
data_sock = accept(sock,NULL,0);
/*
so now you have established connection and
you can send/receive streamming data with calling
read()/write() passing data_sock as target file descriptor.
for example receive a string message :
*/
memset(rmsg,0,sizeof(rmsg));
read(data_sock,rmsg,sizeof(rmsg)-1);
fprintf(stdout,“client send message is: %s\n”,rmsg);
/*
…and write reply
*/
write(data_sock,smsg,sizeof(smsg);
/* close connection */
close(data_sock);
}
/* at exit close listen socket */
close(sock);
- from your sender host programm (let call it client) you should open tcp
socket,
assign needed address info, connect to server and transmit all needed data.
kind of :
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define LISTEN_PORT 1234 /* this is a tcp port you wish to listen on
*/
static const char smsg[] = “client send message”;
static char rmsg[100];
struct sockaddr_in sa;
int sock,data_sock;
/* create tcp socket */
sock = socket(AF_INET,SOCK_STREAM,0);
/*
bind server address info to created socket
let assume that you assigned addres 192.168.1.1 to your server
during ppp connection handshake
/
memset(&sa,0,sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr(“192.168.1.1”); / receive
requests from any ip address /
sa.sin_port = htons(LISTEN_PORT)
bind(sock,(struct sockaddr)&sa,sizeof(sa));
/* connect to server /
connect(sock,(struct sockaddr)&sa,sizeof(sa));
/*
so now you have established connection with server
and can send/receive data with write()/read
passing sock as target file descriptor
*/
/* send test message */
write(sock,smsg,sizeof(smsg));
/* …and read server reply */
memset(rmsg,0,sizeof(rmsg));
read(sock,rmsg,sizeof(rmsg)-1);
fprintf(stdout,“server reply message is: %s”,rmsg);
/* close socket at exit */
close(sock);
well, as you can see, communicating over dial-up line with tcp/ip is
pretty easy and is very simular to raw serial channel communication. look at
examples included in tcp/ip development distribution and hope it becomes
absolutely clear to you.
// wbr
I have developed a serial communication program for data transfer on
RS232 serial connectivity between two computers running QNX 4.25. The
serial
program modules are as follows :
The program at one end is running in MASTER mode. This program’s role is
to
transmit query command packets on the serial line. It then waits for a
response packet from SLAVE. If SLAVE does not respond within 800milliSec,
MASTER indicates a timeout error and prepares next quey packet for
transmission.
At the other end communciation program runs in SLAVE (listening) mode.
This
module normally remains blocked on incoming serial data . If a valid
packet is received on serial port, SLAVE transmits a response packet
with
data to MASTER.
Both the modules are tested and found working on a dedicated serial
connection. Now I wish to use the same program modules over a serial,
dial-up line. Do I need to make major modifications in my source code? I
have used Watcom C compiler version 10.6 with QNX 4.25. Will a “modem
handler” of QNX be of any use?
I have already tried a dial-up connectivity between two QNX computers
(with
“qtalk” for dialing from one computer and “tinit, modem” utilities at the
other end to answer a call and start a “login” session). That worked, but
I
would want my programs to communicate for data transfer over a dialup
serial
line.
Can anyone help me?
Thanks in advance,
Krupa
Ian Zagorskih
Novosoft CyBearNet Department
Custom software development and web design since 1992
E-mail: ianzag@novosoft.ru
Phone: +7 (3832) 39-72-60, 39-72-61
Fax: +7 (3832) 39-63-58
For more visit www.novosoft-us.com