CBBS Server v1.0 - Overview | History | Features | Screenshots | Technology | FAQ
 

History

This project not only taught me how to implement network communications via TCP and MySQL database connectivity, but also how to write a complete message base system which utilizes a line-based editor subsystem for writing and editing messages and how to implement Xmodem file transfers for supporting uploading and downloading files to and from the file libraries. ;) Originally, this project started out simply as a proof-of-concept project. I always wanted to write my own BBS emulation software in Java, after having written numerous client-server applications in Java in the past for various projects.

Normally, server applications written in Java use the in.readLine() method to get the text line entered on the client terminal after the [ENTER] key is pressed. So, I needed to modify the read routine to listen for each key pressed instead, similar to how characters are read into a buffer of a serial communications modem one at a time.

I started out writing a simple EchoKeyServer console server application which printed out the ASCII value of each key pressed (received from the client terminal) on the client side. (The code is shown on the right)

This worked. However, PETSCII emulation displays characters in uppercase that should be lowercase on a standard ASCII compliant terminal emulation program, such as telnet, so I had to write a translation routine that switches the case of characters (A-Z and a-z).

View the PETSCII emulation specification.

Return to previous page

  The code snippet that started the ball rolling is shown below. This example creates a TCP server socket on the specified port, which listens for an incoming client connection. After a connection is made to the server, I/O streams are created for the client socket accepted. The while loop routine reads each key pressed, echos the value back to the client, and prints out the code on the server console screen. This demo does not support multiple connections and exits after the client disconnects. However, it was and still is very useful for testing for and learning about PETSCII emulation concepts, since PETSCII codes instead of ASCII codes are printed out on the server screen when CGTerm is used to connect to it instead of a standard telnet terminal.

import java.io.*; 
import java.net.*; 
  
/*
   An echo server example that echoes any keys pressed 
   on the client terminal and prints out the ASCII value
   of the key pressed to the server console screen
*/

public class EchoKeyServer { 

  public static void main(String[] args)
    throws IOException { 
  
    int port = Integer.parseInt(args[0]); 
    
    // create the server socket
    
    ServerSocket server = new ServerSocket(port); 
    
    System.out.println("Waiting for client connection.");
    
    // wait for an incoming client connection
    
    Socket client = server.accept(); 
        
    // handle the incoming client connection and then exit
    
    try { 
    
      // create I/O streams for the client connection
      
      InputStream in = client.getInputStream(); 
      OutputStream out = client.getOutputStream(); 
       
      // print line of text on client terminal
      
      new PrintStream(out).println("Begin typing."); 
      
      // print ASCII character on client terminal
      
      out.write(13); // print new line
      
      // the loop to listen for any keys pressed
      
      int x; 
      
      while((x = in.read()) > -1) {
      
        // print the ASCII character on client terminal
        
        out.write(x); 
        System.out.println("key code: " + x);
      }
      
    } finally { 
    
      // clean up
      
      client.close(); 
      server.close(); 
    } 
  } 
}


Telnet client connected to server
using ASCII terminal emulation


ASCII codes printed out on server
by using standard telnet client


PETSCII codes printed out on server
by using CGTerm as the client