Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Sockets via .NET to J2E


Message #1 by "Paul Distant" <pear@p...> on Thu, 13 Feb 2003 16:55:19
Sockets via .NET to J2E
Hi I've written a java server that processes request made from external 
applications. It works fine when using telnet(for testing) but fails when 
I create an ASP.NET script using vb.

The problem I have is this:
1. When connecting the the server via asp.net i get a response 
(connection=1)
try  
  tcpClient.Connect(request.form("ServerIP"),request.form("Port"))
  catch ex as exception  
  ...
end try
netstream = tcpClient.GetStream()  
thisResponse=GetResponse(netstream)  
Response.Write("First: " & trim(thisResponse) & "<BR>")

When the script tries to send a command to the server it just hangs.
The server does not receive any data.

thisResponse = SendCommand(netstream,"1")
thisResponse=GetResponse(netstream)  
Response.Write("Second: " & trim(thisResponse) & "<BR>")

'-- send command is basically
Function SendCommand(byRef netstream as  
System.Net.Sockets.NetworkStream,byVal sToSend as String)  
Dim bData() as Byte = Encoding.ASCII.GetBytes(sToSend.ToCharArray)  
netstream.Write(bData,0,bData.Length())  
Return GetResponse(netstream)  
End Function  

The java server that accepts sockets is:
try {
      while (true) {
	if (socket == null) {
	  return;
	}
        InputStreamReader sin = new InputStreamReader(socket.getInputStream
());
	inbuff = new BufferedReader(sin);
	sout = new PrintWriter(new BufferedOutputStream
(socket.getOutputStream()), false);

	String outLine;
	while (true) {
	  String inLine = inbuff.readLine();
	  if (inLine.length() > 0) {
	      if (inLine.equals("disconnect")) {
		System.out.println("disconnecting...");
		break;
	        }
	      //Test menu option
	      outLine = "menu=1";
	  } else{
   	      outLine = "error=unknown menu command";
	  }
	  sout.println(outLine);
	  sout.flush();
	}// end inner while
        closeObj(inbuff);
        sout.close();
      }// end outer while
    } //end try

I'm not sure what's happening so I may write a perl client to see if the 
same thing happens. 
Does anyone have any ideas and does System.Net.Sockets.TcpClient() support 
flush()?

Cheers
Paul

  Return to Index