I’m trying to get my application up and running but I have some trouble
starting. I am using some code that I found on openQNX to get the connection.
I have read this topic: openqnx.com/index.php?name=P … pic&t=8140
I was hoping that I will manage to connect to a 23 port from my QNX
but unfortunately the connect() returns -1;
HELP! I would like to know how to connect to remote hosts.
I got such an environment
Windows Vista
(+ Telnet Server )
192.168.11.103---------------------------------------192.168.11.100 @SH7760 with QNX
QNX application code:
[i]char dest_ip[]=“192.168.1.103”;
int dest_port=23;
char *packet_ptr = NULL;
int n;
int sfd;
struct sockaddr_in sa_in;
int send_bytes = 0;
int recv_bytes = 0;
memset(&sa_in,0,sizeof(sa_in));
if ( (sfd = socket(AF_INET, SOCK_STREAM, 0)) == SOCKET_ERROR)
{
// Code for sending error message
return 0;
}else{
//Code for sending info message
}
sa_in.sin_family = AF_INET;
sa_in.sin_addr.s_addr = inet_addr(dest_ip);
sa_in.sin_port = htons(dest_port);
if ( (connect(sfd, (struct sockaddr *) &sa_in, sizeof(sa_in))) == SOCKET_ERROR)
{
//Code for sending error message
return 0;
} else {
//Code for sending information message
}[/i]
connects returns -1
The port on Vista is open ( can telnet to it), firewall is off
Can ping form vista to sh and form sh to vista
Wireshark shows no activity to 23 port
Are you SURE it’s 192.168.1.103 and not 192.168.11.103. Either you description is wrong or the code is wrong.
Micro: if the netmask is 255.255.0.0 they can be on the same subnet. Plus the OP mentionned it would ping and telnet to the vista machine, I guess it’s safe to assume everything is ok config wise.
I change the first line to memset(&server, 0, sizeof(server)); because I was not compiling.
I got an error on the 4th line - incompatible types in assignment
I wonder - do You think its a good idea to put a loop in which the connections are
accepted and the messages received in a separate thread?
( I’m using PhAB If anyone asks)
That’s up to you whether or not you want to split it up like that.
Here is a nice sample program that I think does what you want (accept new connections and handle incoming messages) using just 1 loop (look for the cheesy multi-person chat server code sample).