* Ada interface to Jave network socket
@ 2000-05-28 0:00 Richard Y. C. Lee
2000-05-29 0:00 ` nabbasi
0 siblings, 1 reply; 2+ messages in thread
From: Richard Y. C. Lee @ 2000-05-28 0:00 UTC (permalink / 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();
}
}
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Ada interface to Jave network socket
2000-05-28 0:00 Ada interface to Jave network socket Richard Y. C. Lee
@ 2000-05-29 0:00 ` nabbasi
0 siblings, 0 replies; 2+ messages in thread
From: nabbasi @ 2000-05-29 0:00 UTC (permalink / raw)
In article <3930B462.66199B57@compuserve.com>, "Richard says...
>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.
You can use Berkeley sockets from Ada. There is a Ada package
for that call AdaSockets.
http://www-inf.enst.fr/ANC/
If the Ada program is the client, and if you are using TCP (not UDP),
simply create a socket() using Java socket address (IP/port), then
call connect() on the socket, then use write() to send data.
for UDP, slightly different calls needs to be used (sendto(), no connection,
see your TCP/IP book for more info).
Nasser
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-05-29 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-28 0:00 Ada interface to Jave network socket Richard Y. C. Lee
2000-05-29 0:00 ` nabbasi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox