This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Can't get sockets to work


Hello,

I am trying to get the code below to work, it is  a simple server app which
echos any text it receives and then dies. The problem is that if compile this
and run it with the JDK all is ok. I telnet my machine on port 7070 type in
something and get 'Echo: something'  back.

If I try this with GCJ the server runs but when I telnet to it, it recieves my
input but the 'Echo: something' does not appear on the client side.

Am I doing something woefully wrong here or is there a problem with
ServerSocket or Socket. I tried looking at the file descriptor and socket code
during the weekend but did not have enough time to get really deep. Any help
would be appreciated.

Regards

Lincoln
________________________________________________

import java.net.*;
import java.io.*;
import java.util.*;

public class testserv {
	
	public static void main(String[] args) {
	
		int port;
		
		try {		
			ServerSocket scon = new ServerSocket(7070);
			System.out.println("Accepting connections on port " + scon.getLocalPort() );
			
			// main loop for service
			while (true){
			
				Socket conn = scon.accept();
				System.out.println("Got request");
				
				DataInputStream is = new DataInputStream( conn.getInputStream() );
				PrintStream os = new PrintStream( conn.getOutputStream() );
				
				String request = is.readLine();
				System.out.println(request);
									
				os.print( "Echo: " + request + "\r\n");
	
				conn.close(); 
                                                                scon.close();
				
				System.exit(0);
			}
		}
		catch (Exception e) {
			
			e.printStackTrace();
			System.out.println(e);
		}
	}
}	

--
------------------------------------------------------------------------------

Lincoln Spiteri

Manufacturing Systems
STMicroelectronics, Malta

e-mail: lincoln.spiteri@st.com

------------------------------------------------------------------------------

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]