Windows 2000 'hanging' IP ports

Lars H. Larsen, ICCC LHL@REDACTED
Mon Feb 3 15:28:45 CET 2003


Hello to all Guru's and wizards
does anybody have expirence here ???

I have a client/server application that did run fine with the socket library in earlier OTP releases , but after an upgrade to  OTP R9 -0 I have to use gen_tcp and it gives me problems in Win2k and XP

I made a small test application to isolate the problem.
you'll  find it below 

-when the client dies , there is no problems when reconnecting  and data xfer later

but if the server dies they seem to reconnet but The data xfer is fucked up it's just "TIMEOUT" on both ends.

the program automatically descide wether it should be server or client.

what is happening ??

Regards Lars Larsen

__________________________________________ cut her


-module(test).

-export([start/2]).
-record(socket,{ip, datsoc,	listsoc,type}).

start(Name,Iterations) when integer(Iterations) ->
	start(Name,5999,Iterations).

start(Name,Port,Iterations) ->  
	 case gen_tcp:connect(Name,Port, [{packet,2},{active,true},{reuseaddr, true}]) of
		{error,_Reason} -> 
				io:format("connect error ~p~n",[_Reason]),
				runserver(Name,Iterations,Port);
			
		{ok,Socket} ->
			io:format("Client~n"),
			gen_tcp:send(Socket,"go ahead server"),
			clientping(Iterations,#socket{type=client ,datsoc = Socket, ip = Name})

							
	end.
	

clicon(Iterations,Rec)->
		gen_tcp:close(Rec#socket.datsoc),
		%io:format("~p~n",[erlang:ports()]),

		case gen_tcp:connect(Rec#socket.ip,5999, [{packet,2},{active,true},{reuseaddr, true}]) of
 			{ok,Socket} ->
				clientping(Iterations,Rec#socket{type=client ,datsoc = Socket});
			{error,_X} ->
				clicon(Iterations,Rec);
			_P	 -> io:format("clicon ~p~n",[_P])
		end.



runserver(Name,Iterations,Port) ->
		io:format("Server~n"),
		case gen_tcp:listen(Port,[{packet, 2}, {active,true},{reuseaddr, true}]) of
		{error,_Any}	->
				io:format("Listen result ~p~n",[_Any]);
		{ok,ListenSocket} ->
					io:format("Listen ok~n"),
					{ok,Socket}= gen_tcp:accept(ListenSocket),
					io:format("Accepted ok ~p ~n",[Iterations]),
					serverping(Iterations,#socket{type=server,datsoc = Socket,listsoc=ListenSocket,ip=Name})
		end.
				
clientping(0,Rec) ->
		gen_tcp:close(Rec#socket.datsoc),
		io:format("the end ~n");
clientping(Iterations,Rec) ->
		%io:format("Loop ~p  Rec ~p  ~n",[Iterations,Rec]),
		receive
		{tcp,Datsoc,Data} ->
 				io:format("~w :GOT Data:~p ~n",[Rec#socket.type,Data]),
				gen_tcp:send(Datsoc,"Are you well"),
				 clientping(Iterations-1,Rec);

		{tcp_closed,Consocket} -> 
					io:format("{tcp_closed,Consocket}~n"),
					clicon(Iterations,Rec);
		 Thing ->
		 		io:format(" ~p :GOT: ~p",[Rec#socket.type,Thing]),
				 clientping(Iterations-1,Rec)
		 		
		 after 1000->
		 		io:format("TIMEOUT ~p ~n",[Rec]),
			 	clientping(Iterations-1,Rec)
 
		 		 			
	 	end.
		
	


serverping(0,Rec) ->
	gen_tcp:close(Rec#socket.datsoc),
	gen_tcp:close(Rec#socket.listsoc),
	io:format("the end ~n");
serverping(Iterations,Rec) ->
		%io:format("Loop ~p  Rec ~p~n",[Iterations,Rec]),
		receive
		{tcp,Datsoc,Data} ->
 			io:format("~w :GOT Data:~p ~n",[Rec#socket.type,Data]),
			gen_tcp:send(Rec#socket.datsoc,"fine Thank you "),
		 serverping(Iterations-1,Rec);
		
		{tcp_closed,Soc} ->
			gen_tcp:close(Rec#socket.listsoc),
			gen_tcp:close(Rec#socket.datsoc),
			runserver(Rec#socket.ip,Iterations,5999);	
			
		 Thing ->
		 			io:format(" ~p :GOT: ~p",[Rec#socket.type,Thing]),
					 serverping(Iterations-1,Rec)
		 			
		 after 1000->
		 			io:format("TIMEOUT ~p ~n",[Rec]),
					 serverping(Iterations-1,Rec)
		 
		 		 			
		 end.
		
	


	
	
	

	





More information about the erlang-questions mailing list