나는 그런 코드를 가지고 :분할 오류 CORBA C의 서버 측에서 (코어 덤프) ++/Java 응용 프로그램
interface Employee
{
string getLastname();
};
#include "Employee.idl"
interface Work
{
Employee getEmployee(in short id);
};
서버 파일 :
#include "Employee.hh"
class EmployeeImpl : public POA_Employee
{
private:
char* lastname;
int id;
public:
EmployeeImpl(const char* lastname, int id);
char* getLastname();
};
#include "EmployeeImpl.h"
EmployeeImpl::EmployeeImpl(const char* lastname, int id)
{
this->lastname = const_cast<char*>(lastname);
this->id = id;
}
char* EmployeeImpl::getLastname()
{
return this->lastname;
}
#include "Work.hh"
#include <vector>
#include "EmployeeImpl.h"
using namespace std;
class WorkImpl : public POA_Work
{
private:
vector<EmployeeImpl> employees;
public:
WorkImpl();
Employee_ptr getEmployee(::CORBA::Short id);
};
#include "WorkImpl.h"
WorkImpl::WorkImpl()
{
EmployeeImpl ei1("Doe", 1);
EmployeeImpl ei2("Smith", 2);
EmployeeImpl ei3("Brown", 3);
employees.push_back(ei1);
employees.push_back(ei2);
employees.push_back(ei3);
}
Employee_ptr WorkImpl::getEmployee(::CORBA::Short id)
{
return employees[id]._this();
}
클라이언트 파일 :
import java.util.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
public class Client
{
public static void main(String [] args)
{
try
{
org.omg.CORBA.ORB clientORB = org.omg.CORBA.ORB.init(args, null);
if (clientORB == null)
{
System.out.println("Problem while creating ORB");
System.exit(1);
}
org.omg.CORBA.Object objRef = clientORB.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
Work work = WorkHelper.narrow(ncRef.resolve_str("WorkService"));
Employee e = work.getEmployee((short)1);
System.out.println(e.getLastname());
e = work.getEmployee((short)2);
System.out.println(e.getLastname());
e = work.getEmployee((short)3);
System.out.println(e.getLastname());
}catch(Exception e){ System.out.println(e.getMessage()); }
}
}
서버를 실행할 때 clien t는, 클라이언트 측에서 나는 참조 :
스미스에게 대신
:
Doe Smith Brown
와 클라이언트가 메시지를 받았을 때, 서버 측에서 내가 참조 :
segmentation fault (co 덤프 됨)
및 서버가 충돌합니다. 내 코드 사람이 뭐라구? 나는 쿠분투에서 omniORB와 idlj를 사용하고 g ++과 javac을 사용하여 파일을 컴파일합니다.
을 Heres 내 전체 프로젝트 :http://www44.zippyshare.com/v/60244821/file.html
업데이트 된 답변보기 –