[Flightgear-devel] A little help with sockets.

2002-04-20 Thread Sergio Roth

I'm testing a code to work as server for FGFS.  When I run FGFS  with 
--native=socket,out,30,linux,ftp  without starting server I get the expected 
message of no possible conection but when I start server before FGFS it runs 
ok. Thus I wonder server is connecting fine but  I don't get anything shown 
on screen. Would someone help me on that?

Thanks.

Sergio Roth 
-- 
Linux user #226380
SuSE Linux 7.2 

/* Program: Comunication test using socket
 (Adapted from GNU C Library Reference manual)
*/

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


#define PORT 5500
#define MAXMSG 5092


int make_socket(unsigned short port)
{
int sock;
struct sockaddr_in name;
/* Create a soquete */
sock=socket(PF_INET, SOCK_STREAM, 0);
if(sock < 0)
  {
  perror("socket");
  exit(EXIT_FAILURE);
  }
name.sin_family=AF_INET;
name.sin_port=htons(port);
name.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(sock, (struct sockaddr *)&name, sizeof(name))<0)
  {
  perror("bind");
  exit(EXIT_FAILURE);
  }
return sock;
}

int read_from_client(int filedes)
{
char buffer[MAXMSG];
int nbytes;
nbytes = read(filedes, buffer, MAXMSG-1);
if(nbytes<0)
  {
  perror("read");
  exit(EXIT_FAILURE);
  }
if(nbytes==0) return -1;
printf("Bytes received:\n%s\n", buffer);
return nbytes;
}


int write_to_client(int filedes, char *msg)
{
int nbytes;
nbytes=write(filedes, msg, strlen(msg)+1);
if(nbytes<0)
  {
  perror("read");
  exit(EXIT_FAILURE);
  }
return nbytes;
}

int main()
{
int sock, newsock, i;

struct sockaddr_in clientname;
fd_set active_fd_set, read_fd_set;
size_t size;

sock=make_socket(PORT);
if(listen(sock,1) < 0)
  {
  perror("listen");
  exit(EXIT_FAILURE);
  }
FD_ZERO(&active_fd_set);
FD_SET(sock, &active_fd_set);

do{
  read_fd_set=active_fd_set;
  if(select(FD_SETSIZE, &read_fd_set, NULL, NULL, NULL)<0)
{
perror("select");
exit(EXIT_FAILURE);
}
  for(i=0; i


Re: [Flightgear-devel] A little help with sockets.

2002-04-21 Thread Erik Hofman

Sergio Roth wrote:
> I'm testing a code to work as server for FGFS.  When I run FGFS  with 
> --native=socket,out,30,linux,ftp  without starting server I get the expected 
> message of no possible conection but when I start server before FGFS it runs 
> ok. Thus I wonder server is connecting fine but  I don't get anything shown 
> on screen. Would someone help me on that?
> 
> Thanks.
> 
> Sergio Roth 
> 
> 
> 
> 
> /* Program: Comunication test using socket
>  (Adapted from GNU C Library Reference manual)
> */
> 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> 
> 
> #define PORT 5500
> #define MAXMSG 5092


Since you are using ftp as a last option for --native I guess you would 
have to use #define PORT 21 here.

You would better try using:

--native=socket,out,30,linux,5500,tcp





___
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel