Haskell <-> C/C++ comunication (sockets/pipes?)

Jorge Adriano jadrian@mat.uc.pt
Thu, 27 Sep 2001 23:06:51 +0100


Can you tell me what is the problem here?
Haskell app  output is redirected to C++ input app (and vice-versa) using 
pipes. (used Erays shell script sugestion)

When I try 
Hsk: 1. get, 2.send
C++: 1. send, 2 get

It works fine, but if I try it the other way around it locks.
C++ app won't get any input.
Seems to me like Hsk is not 'flushing' the output.
If this is the case, I can't really explain why it happens... if the output 
was not redirected I am pretty sure that, before trying to get input the 
output would be flushed
(imagine something like putStrLn "please type an int:")
So what is the issue here?


Here is the code,
And once again, thanks in advance.
J.A.

-------------------------------
Haskell app: send -> get
-------------------------------
main :: IO()
main =  do

	--send hsnum
	putStrLn "6" 

        -- get cnum and save
	num <- readLn :: IO(Int)
	writeFile "./reshs.txt" (show num)


----------------------------
C++ app: get -> send 
----------------------------
#include <cstdio>
#include <iostream>
#include <fstream>

nt main(){
  
  // *get* hsnum and save
  int num;
  ofstream out("rescc.txt");
  cin >> num;
  out << num;
  
  // *send* cnum
  cout << 10 << '\n' << flush;  //it works without the flush

  return 0;
}