From: "Richard Y. C. Lee" <ryclee@compuserve.com>
Subject: Ada interface to Jave network socket
Date: 2000/05/28
Date: 2000-05-28T05:52:28+00:00 [thread overview]
Message-ID: <3930B462.66199B57@compuserve.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 424 bytes --]
I am doing Software Engineering at university. Currently I am working on
an
elevator control project which require writing Ada code to interface
with Java.
The interface is through a tcp socket connection. The Ada code is to
connect with
a network socket created in Java then pass messages across. Enclosed
sample Java code which creates the socket. Anyone with some ideas how
this is done
would be appreciated.
Richard
[-- Attachment #2: ManagerConnect.java --]
[-- Type: text/plain, Size: 2699 bytes --]
//Title: Elevator System
//Version:
//Copyright: Copyright (c) 2000
//Author: David Lowe
//Company: Faculty of Engineering, UTS
//Description:48440: Software Engineering
// Major Project
// Elevator Simulator
//Filename: ManagerConnect.java
import java.awt.*;
import java.io.*;
import java.util.*;
import java.net.*;
public class ManagerConnect implements Runnable
{
String className = "ManagerConnect";
ElevatorController elevCont;
int elevNum;
int elevPort;
boolean verbose;
// Time information
Thread ThreadManIF;
// Constructor
public ManagerConnect(ElevatorController elevCont, int port, boolean verbose, int elevNum)
{
this.elevCont = elevCont;
this.elevPort = port;
this.verbose = verbose;
this.elevNum = elevNum;
// Start the Manager Interface thread
ThreadManIF = new Thread(this, "ThreadManIF");
ThreadManIF.start();
System.out.println(className + ": Manager Interface constructed and running");
}
// Main thread routine
public void run()
{
ServerSocket server;
Socket connection;
String request, response;
DataInputStream ip;
DataOutputStream op;
byte buf[] = new byte[1000];
int numread;
try {
// create the socket for the server
server = new ServerSocket( elevPort, 100 );
System.out.println(className + ": Manager Socket set up on port " + elevPort);
while (true) {
// wait for a connection
connection = server.accept();
ip = new DataInputStream(connection.getInputStream());
op = new DataOutputStream(connection.getOutputStream());
System.out.println(className + ": Connection established on port " + elevPort);
// get messages and respond
do {
// read in the command
numread = ip.read(buf);
request = new String(buf, 0, numread);
// process request
// ### NOTE THIS NEEDS TO BE FINISHED - ALSO NEED TO MAKE
// ### IT MULTITHREADING SO CAN HANDLE MULTIPLE OPERATOR
// ### CONNECTIONS
response = "Fail";
// send the response
if (verbose) System.out.println(className + ": request <" + request + "> - response <" + response + ">");
op.write(response.getBytes());
op.flush();
} while (true);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
next reply other threads:[~2000-05-28 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-05-28 0:00 Richard Y. C. Lee [this message]
2000-05-29 0:00 ` Ada interface to Jave network socket nabbasi
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox