caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Udp connection problem
@ 2007-01-05 19:23 Frederico Valente
  2007-01-06 10:23 ` [Caml-list] " Stéphane Glondu
  2007-01-08 14:27 ` Serge Aleynikov
  0 siblings, 2 replies; 6+ messages in thread
From: Frederico Valente @ 2007-01-05 19:23 UTC (permalink / raw)
  To: caml-list

Hi!

	I am trying to communicate with an udp server currently in my computer.
The problem is that although I can send messages, and they are correctly 
received, I dont get any message back (I should). Running a sniffer I 
get an ICMP Unreacheable (Port Unreacheable) after the server response.
	
	Here is the code I'm using:

let serverPort = 4001;;
let serverAddress = Unix.ADDR_INET(Unix.inet_addr_of_string "127.0.0.1", 
serverPort);;

let open_connection sockaddr =
	let domain = Unix.domain_of_sockaddr sockaddr in
	let sock = Unix.socket domain Unix.SOCK_DGRAM 0 in
	try Unix.connect sock sockaddr ;
		(Unix.in_channel_of_descr sock, Unix.out_channel_of_descr sock)
	with exn -> Unix.close sock; raise exn
;;


let mainLoop =
	let inChannel,outChannel = open_connection serverAddress in

	while true do
		output_string outChannel "(message)";
		flush outChannel;
		let r=input_line inChannel in
		Printf.printf "%s" r;
	done
;;

mainLoop;;

	If there's anyone willing to see if the problem lies in this simple 
code I would be extremely grateful.
	I am compiling with ocamlopt in a 3.2Gh Pentium-d in 32 bits and 
running gentoo linux.

	Thanks in advance!


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Udp connection problem
  2007-01-05 19:23 Udp connection problem Frederico Valente
@ 2007-01-06 10:23 ` Stéphane Glondu
  2007-01-06 16:52   ` Frederico Valente
  2007-01-08 14:27 ` Serge Aleynikov
  1 sibling, 1 reply; 6+ messages in thread
From: Stéphane Glondu @ 2007-01-06 10:23 UTC (permalink / raw)
  To: Frederico Valente; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 410 bytes --]

Frederico Valente a écrit :
>     I am trying to communicate with an udp server currently in my computer.
> The problem is that although I can send messages, and they are correctly
> received, I dont get any message back (I should). Running a sniffer I
> get an ICMP Unreacheable (Port Unreacheable) after the server response.

It sounds like a firewall is filtering your traffic.

-- 
Stephane



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 254 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Udp connection problem
  2007-01-06 10:23 ` [Caml-list] " Stéphane Glondu
@ 2007-01-06 16:52   ` Frederico Valente
  0 siblings, 0 replies; 6+ messages in thread
From: Frederico Valente @ 2007-01-06 16:52 UTC (permalink / raw)
  To: caml-list

Stéphane Glondu wrote:
> Frederico Valente a écrit :
>>     I am trying to communicate with an udp server currently in my computer.
>> The problem is that although I can send messages, and they are correctly
>> received, I dont get any message back (I should). Running a sniffer I
>> get an ICMP Unreacheable (Port Unreacheable) after the server response.
> 
> It sounds like a firewall is filtering your traffic.
> 

Indeed it sounds, but I don't think it is, as I can set up the 
connection using C++.

bool Connection::connect(const char *host, int port )
{
   struct hostent *host_ent;
   struct in_addr *addr_ptr;
   struct sockaddr_in  cli_addr ;
   int    sockfd ;

   m_sock.socketfd = -1 ;

   if( (host_ent = (struct hostent*)gethostbyname(host)) == NULL)
   {
     // if not a string, get information from IP adress.
     if( inet_addr(host) == INADDR_NONE )
     {
       cerr << "(Connection::connect) Cannot find host " << host << endl;
       return false ;
     }
   }
   else   // get the necessary information from the hostname (string)
   {
     addr_ptr = (struct in_addr *) *host_ent->h_addr_list;
     host = inet_ntoa(*addr_ptr);
   }

   //  Open UDP socket.
   if( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
   {
     cerr << "(Connection::connect) Cannot create socket " << host << endl;
     return false ;
   }

   // insert the information of the client
   cli_addr.sin_family      = AF_INET ;
   cli_addr.sin_addr.s_addr = htonl(INADDR_ANY) ;
   cli_addr.sin_port        = htons(0) ;

   // bind the client to the server socket
   if(::bind(sockfd, (struct sockaddr *) &cli_addr, sizeof(cli_addr)) < 0)
   {
     cerr << "(Connection::connect) Cannot bind local address " << host 
<< endl;
     return false ;
   }

   //  Fill in the structure with the address of the server.
   m_sock.socketfd = sockfd ;

   m_sock.serv_addr.sin_family       = AF_INET ;
   m_sock.serv_addr.sin_addr.s_addr  = inet_addr(host);
   m_sock.serv_addr.sin_port         = htons(port) ;

   return true;
}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Udp connection problem
  2007-01-05 19:23 Udp connection problem Frederico Valente
  2007-01-06 10:23 ` [Caml-list] " Stéphane Glondu
@ 2007-01-08 14:27 ` Serge Aleynikov
  2007-01-08 23:58   ` Frederico Valente
  1 sibling, 1 reply; 6+ messages in thread
From: Serge Aleynikov @ 2007-01-08 14:27 UTC (permalink / raw)
  To: Frederico Valente; +Cc: caml-list

Frederico,

I believe the problem is that you are opening a server socket on a local 
address "127.0.0.1" rather than on a publicly-known address (stored in 
DNS) or any ("0.0.0.0"), and therefore only a client on the same host 
will be able to reach the server.

Regards,

Serge

Frederico Valente wrote:
> Hi!
> 
>     I am trying to communicate with an udp server currently in my computer.
> The problem is that although I can send messages, and they are correctly 
> received, I dont get any message back (I should). Running a sniffer I 
> get an ICMP Unreacheable (Port Unreacheable) after the server response.
>     
>     Here is the code I'm using:
> 
> let serverPort = 4001;;
> let serverAddress = Unix.ADDR_INET(Unix.inet_addr_of_string "127.0.0.1", 
> serverPort);;
> 
> let open_connection sockaddr =
>     let domain = Unix.domain_of_sockaddr sockaddr in
>     let sock = Unix.socket domain Unix.SOCK_DGRAM 0 in
>     try Unix.connect sock sockaddr ;
>         (Unix.in_channel_of_descr sock, Unix.out_channel_of_descr sock)
>     with exn -> Unix.close sock; raise exn
> ;;
> 
> 
> let mainLoop =
>     let inChannel,outChannel = open_connection serverAddress in
> 
>     while true do
>         output_string outChannel "(message)";
>         flush outChannel;
>         let r=input_line inChannel in
>         Printf.printf "%s" r;
>     done
> ;;
> 
> mainLoop;;
> 
>     If there's anyone willing to see if the problem lies in this simple 
> code I would be extremely grateful.
>     I am compiling with ocamlopt in a 3.2Gh Pentium-d in 32 bits and 
> running gentoo linux.
> 
>     Thanks in advance!
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Udp connection problem
  2007-01-08 14:27 ` Serge Aleynikov
@ 2007-01-08 23:58   ` Frederico Valente
  2007-01-09 21:24     ` Serge Aleynikov
  0 siblings, 1 reply; 6+ messages in thread
From: Frederico Valente @ 2007-01-08 23:58 UTC (permalink / raw)
  Cc: caml-list

Serge Aleynikov wrote:
> Frederico,
> 
> I believe the problem is that you are opening a server socket on a local 
> address "127.0.0.1" rather than on a publicly-known address (stored in 
> DNS) or any ("0.0.0.0"), and therefore only a client on the same host 
> will be able to reach the server.
> 
> Regards,
> 
> Serge

Well, the server is on my machine, as well as the client. That's why 
I've used that address. I've killed the firewall so that I could rule 
out that source of problems as well. So I guess the problem lies in my 
code... :S


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Udp connection problem
  2007-01-08 23:58   ` Frederico Valente
@ 2007-01-09 21:24     ` Serge Aleynikov
  0 siblings, 0 replies; 6+ messages in thread
From: Serge Aleynikov @ 2007-01-09 21:24 UTC (permalink / raw)
  To: Frederico Valente; +Cc: caml-list

There's not enough details in your email about the server, but if I 
assume that it merely echos your message back to the client, then the 
message would need to contain a new line at the end in order for the 
input_line function to be able to fetch the response line:

     while true do
         output_string outChannel "(message)\n";   (* !!! *)
         flush outChannel;
         let r=input_line inChannel in
         Printf.printf "%s\n" r;
     done

Serge

Frederico Valente wrote:
> Serge Aleynikov wrote:
>> Frederico,
>>
>> I believe the problem is that you are opening a server socket on a 
>> local address "127.0.0.1" rather than on a publicly-known address 
>> (stored in DNS) or any ("0.0.0.0"), and therefore only a client on the 
>> same host will be able to reach the server.
>>
>> Regards,
>>
>> Serge
> 
> Well, the server is on my machine, as well as the client. That's why 
> I've used that address. I've killed the firewall so that I could rule 
> out that source of problems as well. So I guess the problem lies in my 
> code... :S
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 

-- 
Serge Aleynikov
Routing R&D, IDT Telecom
Tel: +1 (973) 438-3436
Fax: +1 (973) 438-1464


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-01-09 21:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-05 19:23 Udp connection problem Frederico Valente
2007-01-06 10:23 ` [Caml-list] " Stéphane Glondu
2007-01-06 16:52   ` Frederico Valente
2007-01-08 14:27 ` Serge Aleynikov
2007-01-08 23:58   ` Frederico Valente
2007-01-09 21:24     ` Serge Aleynikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).