OpenQNX :: The QNX Community Portal

Jul 25, 2008 - 04:01 PM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 23 unlogged users and 3 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
invoker
Post subject: Can't connect to a specified port@address  PostPosted: Apr 18, 2008 - 10:43 AM
Active Member


Joined: Apr 15, 2008
Posts: 32

Hi

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:
http://www.openqnx.com/index.php?name=PNphpBB2&file=viewtopic&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:

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
}



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

what can be wrong?
 
 View user's profile Send private message  
Reply with quote Back to top
mario
Post subject: RE: Can  PostPosted: Apr 18, 2008 - 11:39 AM
QNX Master


Joined: Sep 01, 2002
Posts: 2783

Is this a typo: The source addresses in your code don't match.

192.168.11.103---------------------------------------192.168.11.100 @SH7760 with QNX


char dest_ip[]="192.168.1.103";
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
invoker
Post subject: Re: RE: Can  PostPosted: Apr 18, 2008 - 02:37 PM
Active Member


Joined: Apr 15, 2008
Posts: 32

mario wrote:
Is this a typo: The source addresses in your code don't match.

192.168.11.103---------------------------------------192.168.11.100 @SH7760 with QNX


char dest_ip[]="192.168.1.103";


the code is running on SH7760 with QNX
source ip is 192.168.11.100 and the dest ip 192.168.1.103

so its correct?
 
 View user's profile Send private message  
Reply with quote Back to top
micro
Post subject:   PostPosted: Apr 18, 2008 - 03:33 PM
Senior Member


Joined: Jul 22, 2004
Posts: 333

Can you connect in any way to the qnx machine?

So telnet, ftp similar?
Since they belong to other subnets they would need to have a router in between.
 
 View user's profile Send private message  
Reply with quote Back to top
mario
Post subject:   PostPosted: Apr 18, 2008 - 04:09 PM
QNX Master


Joined: Sep 01, 2002
Posts: 2783

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.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
invoker
Post subject:   PostPosted: Apr 18, 2008 - 06:08 PM
Active Member


Joined: Apr 15, 2008
Posts: 32

mario wrote:
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.


good point - need to check it on Monday Cool thx
 
 View user's profile Send private message  
Reply with quote Back to top
invoker
Post subject:   PostPosted: Apr 21, 2008 - 07:57 AM
Active Member


Joined: Apr 15, 2008
Posts: 32

thanks for picking up my mistake!
beside that the code works Smile

thx!
 
 View user's profile Send private message  
Reply with quote Back to top
micro
Post subject:   PostPosted: Apr 21, 2008 - 12:55 PM
Senior Member


Joined: Jul 22, 2004
Posts: 333

Oh ^^ i did not see that ping works.
*Read carefully again ^^*
 
 View user's profile Send private message  
Reply with quote Back to top
invoker
Post subject:   PostPosted: Apr 30, 2008 - 08:24 AM
Active Member


Joined: Apr 15, 2008
Posts: 32

I need some more help :/
There are many pieces of code that I found on the internet but most of them
are not working :/

I need to listen to a specific tcp port and throw what I receive to a buffer:

int sock;
struct sockaddr_in server;
int msgsock;
char buf[1024];
int rval;

sock = socket(AF_INET, SOCK_STREAM, 0);
server.sin_family = AF_INET;
server.sin_port = 1666;
bind(sock, (struct sockaddr *)&server, sizeof(server));

listen(sock, 5);
do {
msgsock = accept(sock, 0, 0);
if (msgsock == -1)
{
return EXIT_FAILURE;
} else
do {
memset(buf, 0, sizeof(buf));
rval = read(msgsock, buf, 1024);
PtTextModifyText( ABW_PtText1, 0, 0, -1, buf,sizeof(buf));
} while (rval > 0);
close(msgsock);
} while (1);

Could anyone have a quick look at this and tell me why its wrong?
Thanks! Smile
 
 View user's profile Send private message  
Reply with quote Back to top
mario
Post subject:   PostPosted: Apr 30, 2008 - 11:36 AM
QNX Master


Joined: Sep 01, 2002
Posts: 2783

you need to use hton on the assignement to sin_port otherwise I thing you end up with using port 6616
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
mezek
Post subject:   PostPosted: Apr 30, 2008 - 12:39 PM
Senior Member


Joined: Mar 03, 2004
Posts: 185

memset(&server, 0, sizeof(sockaddr_in));
server.sin_family = AF_INET;
server.sin_port = htons(1666);
server.sin_addr = INADDR_ANY;
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
invoker
Post subject:   PostPosted: Apr 30, 2008 - 01:07 PM
Active Member


Joined: Apr 15, 2008
Posts: 32

memset(&server, 0, sizeof(sockaddr_in));
server.sin_family = AF_INET;
server.sin_port = htons(1666);
server.sin_addr = INADDR_ANY;

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 :/
 
 View user's profile Send private message  
Reply with quote Back to top
mezek
Post subject:   PostPosted: Apr 30, 2008 - 01:28 PM
Senior Member


Joined: Mar 03, 2004
Posts: 185

yea, sorry, i meant
memset(&server, 0, sizeof(struct sockaddr_in));
and
server.sin_addr.s_addr = INADDR_ANY;
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
invoker
Post subject:   PostPosted: Apr 30, 2008 - 02:10 PM
Active Member


Joined: Apr 15, 2008
Posts: 32

mezek wrote:
yea, sorry, i meant
memset(&server, 0, sizeof(struct sockaddr_in));
and
server.sin_addr.s_addr = INADDR_ANY;


Thank you mezek and mario Smile

As I'm developing under windows I had to think a way to test it.
I found this code in C# tcp server and client in c#


I still got a problem that my server on qnx receives only first message but I will get to the bottom of this.

Both the client and the server written for qnx works - if anyone will
in the future run into this post.
 
 View user's profile Send private message  
Reply with quote Back to top
invoker
Post subject:   PostPosted: Apr 30, 2008 - 02:17 PM
Active Member


Joined: Apr 15, 2008
Posts: 32

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)
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.