新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   >>中国XML论坛<<     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论Semantic Web(语义Web,语义网或语义万维网, Web 3.0)及相关理论,如:Ontology(本体,本体论), OWL(Web Ontology Langauge,Web本体语言), Description Logic(DL, 描述逻辑),RDFa,Ontology Engineering等。
    [返回] 中文XML论坛 - 专业的XML技术讨论区W3CHINA.ORG讨论区 - Web新技术讨论『 Semantic Web(语义Web)/描述逻辑/本体 』 → [求助]如何在vs中利用jena控制owl本体? 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 13656 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [求助]如何在vs中利用jena控制owl本体? 举报  打印  推荐  IE收藏夹 
       本主题类别: Ontology Engineering    
     campbell 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:6
      积分:76
      门派:XML.ORG.CN
      注册:2010/10/9

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给campbell发送一个短消息 把campbell加入好友 查看campbell的个人资料 搜索campbell在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看campbell的博客楼主
    发贴心情 [求助]如何在vs中利用jena控制owl本体?

    如题,真的急切的想知道是否有相应的类库或者解决方法,跪谢各位啊!
    在这里看过一个方法,但有些工具的旧版我还找不到,

    http://apps.hi.baidu.com/share/detail/17948269

    非常非常感谢各位!


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/10/20 1:01:00
     
     laotao 帅哥哟,离线,有人找我吗?
      
      
      威望:1
      等级:大四(GRE考了1400分!)
      文章:117
      积分:1030
      门派:XML.ORG.CN
      注册:2007/4/30

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给laotao发送一个短消息 把laotao加入好友 查看laotao的个人资料 搜索laotao在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 点击这里发送电邮给laotao 引用回复这个贴子 回复这个贴子 查看laotao的博客2
    发贴心情 
    一种方法是将jena转换成.net的dll, 有个java to .net的开源工具(忘记啥名字了), 不过好像很麻烦
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/10/20 9:31:00
     
     liuytliuyt 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(汇编考了97分!)
      文章:31
      积分:333
      门派:XML.ORG.CN
      注册:2007/9/18

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给liuytliuyt发送一个短消息 把liuytliuyt加入好友 查看liuytliuyt的个人资料 搜索liuytliuyt在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看liuytliuyt的博客3
    发贴心情 
    可以用socket,通过VS与JAVA的通信来实现,我就是这样实现的
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/10/20 14:38:00
     
     大黑皮 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:59
      门派:XML.ORG.CN
      注册:2010/10/24

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给大黑皮发送一个短消息 把大黑皮加入好友 查看大黑皮的个人资料 搜索大黑皮在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看大黑皮的博客4
    发贴心情 
    你好,能具体说说vs与java是怎么通信的/
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/10/24 15:45:00
     
     liuytliuyt 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(汇编考了97分!)
      文章:31
      积分:333
      门派:XML.ORG.CN
      注册:2007/9/18

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给liuytliuyt发送一个短消息 把liuytliuyt加入好友 查看liuytliuyt的个人资料 搜索liuytliuyt在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看liuytliuyt的博客5
    发贴心情 
    c#段关键代码
    ------------
            private void getclspropsocket(string clsname)
            {
                try
                {

                    IPAddress ip = IPAddress.Parse(host);
                    IPEndPoint ipe = new IPEndPoint(ip, port);//把ip和端口转化为IPEndPoint实例

                    Socket c = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个Socket
                    c.Connect(ipe);//连接到服务器
                    string sendStr = "Convert:" + clsname;
                    byte[] bs = Encoding.Default.GetBytes(sendStr);
                    c.Send(bs, bs.Length, 0);//发送信息

                    NetworkStream ns = new NetworkStream(c);
                    FileStream fs = new FileStream(@"C:\test\convertname.xml", FileMode.OpenOrCreate);

                    bool isRead = true;

                    byte[] receiveBuf = new byte[1024];
                    while (isRead)
                    {
                        count = ns.Read(receiveBuf, 0, receiveBuf.Length);

                        if (count > 0 && count <= receiveBuf.Length)
                        {
                            isRead = true;
                            fs.Write(receiveBuf, 0, count);

                        }
                        else
                        {
                            isRead = false;
                        }

                    }

                    fs.Close();
                    c.Close();
                }
                catch (Exception e1)
                {
                    MessageBox.Show(e1.ToString());
                }
            }

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/10/25 15:37:00
     
     liuytliuyt 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(汇编考了97分!)
      文章:31
      积分:333
      门派:XML.ORG.CN
      注册:2007/9/18

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给liuytliuyt发送一个短消息 把liuytliuyt加入好友 查看liuytliuyt的个人资料 搜索liuytliuyt在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看liuytliuyt的博客6
    发贴心情 
    java端代码
    -----------
    文件1
    package test;

    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.Socket;


    public class SendFileClient
    {

     private static final int Server_PORT = 6000;
     

     public static void main( String[] args ) throws IOException
     {

      System.out.println( "This is client" );

      byte[] buf = new byte[100];
      byte[] name = new byte[100];
      
      String ipStr = "127.0.0.1";

      
      try
      {
       // 创建一个Socket
       Socket s = new Socket(ipStr , Server_PORT);
       //s.connect ( new InetSocketAddress (ipStr , Server_PORT ), Client_PORT );
       OutputStream os = s.getOutputStream( );// 输出流
       InputStream is = s.getInputStream( );// 输入流
       
       //向服务器传送文件
    //   int len = is.read( buf );// 从输入流中读取数据到buf   
    //   String revStr = new String( buf, 0, len );
       os.write( "file:lytserver.txt".getBytes( ));//表示将要传递文件
       int len = is.read( buf );// 从输入流中读取数据到buf   
       String revStr = new String( buf, 0, len );
       if ( revStr.equals("well"))//表示服务器端准备好了接受文件
       {
        FileInputStream fins = new FileInputStream("server.txt");
        //byte[] fielBuf = new byte[100];
        int data;
        while ( -1 != ( data = fins.read( ) ) )//从文件中读取数据,每次读取1字节
        {
         os.write( data ); //将读取到的数据写到网络数据流中发送给客户段
        }
       }
       
       os.close( );
       is.close( );
       s.close( );
      } catch ( Exception ex )
      {
       ex.printStackTrace( );
      }
     } 

    }

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/10/25 15:40:00
     
     liuytliuyt 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(汇编考了97分!)
      文章:31
      积分:333
      门派:XML.ORG.CN
      注册:2007/9/18

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给liuytliuyt发送一个短消息 把liuytliuyt加入好友 查看liuytliuyt的个人资料 搜索liuytliuyt在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看liuytliuyt的博客7
    发贴心情 
    java端
    文件2
    ------------
    package test;


    import java.net.*;
    import java.awt.Dimension;
    import java.awt.Menu;
    import java.awt.MenuBar;
    import java.awt.MenuItem;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.*;

    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;

    import edu.stanford.smi.protegex.owl.model.OWLModel;

    /**
    * 服务器程序,用于传输文件

    */
    public class SendFileSocket extends Thread
    {
        public  static JFrame parent=null;  //用于返回父窗体
        private JFrame frame = null;
        private JPanel pane = null;
        private JLabel label1=new JLabel("集成服务状态:未启动");
        private MenuBar mb=new MenuBar();     
        private Menu m1=new Menu("服务");
     private MenuItem start=new MenuItem("开始"),stop=new MenuItem("停止"),exit=new MenuItem("退出");
     private ServerSocket ss;
     
        private volatile boolean running;  //服务器正在运行的标志
     
     public static void main( String[] args )
     {
      server( );//启动服务器程序
     }

     private static final int PORT  = 6000;
     private Socket    s;
     private static  String  owlfileA=null,owlfileB=null;

        
     public SendFileSocket( )
     {
      try
      {
            frame = new JFrame();
            pane = new JPanel();
            label1.setSize(new Dimension(100,100));
            label1.setBounds(new Rectangle(50, 50, 300, 80));
         label1.setFont(label1.getFont().deriveFont(25f));    
         
            
            pane.setLayout(null);
            pane.add(label1);
            
            mb.add(m1);  
      m1.add(start);
      m1.add(stop);
      m1.add(exit);
      
      ss = new ServerSocket( PORT );
      //ss.setSoTimeout(2000);
      
      start.addActionListener(new ActionListener(){
       public void actionPerformed(ActionEvent e)
       {
                   try
                   {
                    startServer();
                    label1.setText("集成服务状态:已启动");
                        pane.add(label1);
                        frame.setVisible(true);
                        System.out.println( "This is server" );
                  int count = 0;
                  while (running)
                  {
                   // 创建一个Socket等待客户端连接
                   //
                   try
                   {
                    Socket s = ss.accept( );
                       count++ ;
                       System.out.println( "This is the " + count + "'st client connetion!" );
                       new SendFileSocket( s ).start( );// 启动一个线程为这个客户端服务
                      }
                      catch (Exception ex)
                      {
                         this.wait(10);
                         break;
                      }
                      
                  }

                  //server( );//启动服务器程序              

                 }
                 catch (Exception ex)
                 {
                    //ex.printStackTrace();
                 }    
       }
      });
      
      stop.addActionListener(new ActionListener(){
       public void actionPerformed(ActionEvent e)
       {
                   try
                   {
                    startServer();
                    ss.close();
                  label1.setText("集成服务状态:已停止");
                        pane.add(label1);
                        frame.setVisible(true);
                  
                 }
                 catch (Exception ex)
                 {
                    ex.printStackTrace();
                 }    
       }
      });
      
      exit.addActionListener(new ActionListener(){
       public void actionPerformed(ActionEvent e)
       {
                   try
                   {
         parent.setVisible(true);
         frame.dispose();
                 }
                 catch (Exception ex)
                 {
                    ex.printStackTrace();
                 }    
       }
      });


            frame.getContentPane().add(pane);
            frame.setMenuBar(mb);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(400, 300);
            frame.setLocation(50, 150);
            frame.setResizable(false);
            frame.setVisible(true);
      }
      catch ( Exception e )
      {
       e.printStackTrace( );
      }
            
     }

     public SendFileSocket( Socket s )
     {
      this.s = s;
     }
     
     

     public void run()
     {
      try
      {   
       OutputStream os = s.getOutputStream( );
       InputStream is = s.getInputStream( );
       FileInputStream fins;
       int data;
       String clientName;
       
       Convert convert=new Convert(true);
       
       //os.write( "Hello,welcome you!".getBytes( ) );
       byte[] buf = new byte[100];
       while ( true )
       {
        int len = is.read( buf );
        String revStr = new String( buf, 0, len );
        System.out.println( "This client wants to "+revStr );

        if ( revStr.startsWith( "Login" ) )//表明客户端请求传输一个文件
        {
         clientName = getFileName(revStr );
         owlfileA=getowlfilename(clientName);//获取本体文件名

         convert.creatallnameXML(clientName);
         //传递所有参与协作系统名
         fins = new FileInputStream("allname.xml");
         //byte[] fielBuf = new byte[100];

         while ( -1 != ( data = fins.read( ) ) )//从文件中读取数据,每次读取1字节
         {
          os.write( data ); //将读取到的数据写到网络数据流中发送给客户段
         }
         
         fins=null;
         
         break;
         
        }

        // 传递目标系统名

        if ( revStr.startsWith( "Object" ) )
        {
         String[] name=getFileName(revStr).split(":");
         String nameA=name[0];
         String nameB=name[1];

         //convert.getfilename(); //获取文件名前缀result.txt中
         convert.creatclsxml(nameA,nameB);
         fins = new FileInputStream("objectclass.xml");     
         //byte[] fielBuf = new byte[100];

         while ( -1 != ( data = fins.read( ) ) )//从文件中读取数据,每次读取1字节
         {
          os.write( data ); //将读取到的数据写到网络数据流中发送给客户段
         }
         
         fins=null;
         
         break;
        }

        
        // 传递目标系统名

        if ( revStr.startsWith( "Convert" ) )//表明客户端请求传输一个文件
        {
         String[] name=getFileName(revStr).split(":");
         String nameA=name[0];
         String nameB=name[1];
         String nameC=name[2];
         convert.creatclspropertyxml(nameA,nameB,nameC);
         
         fins = new FileInputStream("convertname.xml");
         //byte[] fielBuf = new byte[100];

         while ( -1 != ( data = fins.read( ) ) )//从文件中读取数据,每次读取1字节
         {
          os.write( data ); //将读取到的数据写到网络数据流中发送给客户段
         }
         fins=null;
         break;
        }

        
        // 客户传递请求转换文件
        
        if ( revStr.startsWith( "File" ) )//表明客户端请求传输一个文件
        {     
         //fileName = getFileName(revStr );
         os.write("well".getBytes( ));
         
         byte[] filedata=new byte[0];
         
         len = is.read( buf );

         while (len!= -1)
         { 

          if (len>0)
          {       
           String str=new String( buf,"gb2312");       
           byte[] temp=new byte[filedata.length+len];
           if (len==100)  //前面部分完整数据
           {
            for (int i=0;i<filedata.length;i++)
            {
             temp[i]=filedata[i];
            }
            for (int i=0;i<buf.length;i++)
            {
             temp[filedata.length+i]=buf[i];
            }
           }
           else    //前面部分完整数据
           {
            for (int i=0;i<filedata.length;i++)
            {
             temp[i]=filedata[i];
            }
            for (int i=0;i<len;i++)
            {
             temp[filedata.length+i]=buf[i];
            }
           }
           
           filedata=temp;
          }
          try
          {
            if(is.available()>0)
            {
           len =is.read(buf);
            }
            else
            {
             len=-1;
            }
          }
          catch ( Exception e )
          {
           len=-1;
           e.printStackTrace( );
          }
         } 

         try
         {
          String s=new String( filedata,"gb2312");
                BufferedWriter bw=new BufferedWriter(new FileWriter("convert.xml"));

                   if (s!=null)
                   {
                    bw.write(s);            
                   }
                   bw.close();


          System.out.println("\nFile has been recerved successfully.");

         }
         catch ( Exception e )
         {
          System.out.println("\nfile save error.");
          e.printStackTrace( );
         } 

         //转换后传送给客户端
         convert.convertontoXML();
         fins = new FileInputStream("convertresult.xml");
         while ( -1 != ( data = fins.read( ) ) )//从文件中读取数据,每次读取1字节
         {
          os.write( data ); //将读取到的数据写到网络数据流中发送给客户段
         }
         
         fins=null;
         
         break;     
        }        
        
        if ( revStr.startsWith( "query" ) )//表明客户端请求传输一个文件
        {     
         //fileName = getFileName(revStr );
         os.write("well".getBytes( ));     
         byte[] filedata=new byte[0];     
         len = is.read( buf );
         while (len!= -1)
         { 
          if (len>0)
          {       
           String str=new String( buf,"gb2312");       
           byte[] temp=new byte[filedata.length+len];
           if (len==100)  //前面部分完整数据
           {
            for (int i=0;i<filedata.length;i++)
            {
             temp[i]=filedata[i];
            }
            for (int i=0;i<buf.length;i++)
            {
             temp[filedata.length+i]=buf[i];
            }
           }
           else    //前面部分完整数据
           {
            for (int i=0;i<filedata.length;i++)
            {
             temp[i]=filedata[i];
            }
            for (int i=0;i<len;i++)
            {
             temp[filedata.length+i]=buf[i];
            }
           }       
           filedata=temp;
          }
          try
          {
            if(is.available()>0)
            {
           len =is.read(buf);
            }
            else
            {
             len=-1;
            }
          }
          catch ( Exception e )
          {
           len=-1;
           e.printStackTrace( );
          }
         }
         try
         {
          String s=new String( filedata,"gb2312");
                BufferedWriter bw=new BufferedWriter(new FileWriter("query.xml"));

                   if (s!=null)
                   {
                    bw.write(s);            
                   }
                   bw.close();
          System.out.println("\nFile has been recerved successfully.");
         }
         catch ( Exception e )
         {
          System.out.println("\nfile save error.");
          e.printStackTrace( );
         } 

         Query query=new Query();
         //传递查询结果文件
         fins = new FileInputStream("queryresult.xml");
         while ( -1 != ( data = fins.read( ) ) )//从文件中读取数据,每次读取1字节
         {
          os.write( data ); //将读取到的数据写到网络数据流中发送给客户段
         }

         fins=null;
         break;     
        }
        
        
        if ( revStr.startsWith( "update" ) )//表明客户端请求传输一个文件
        {     
         //fileName = getFileName(revStr );
         os.write("well".getBytes( ));     
         byte[] filedata=new byte[0];     
         len = is.read( buf );
         while (len!= -1)
         { 
          if (len>0)
          {       
           String str=new String( buf,"gb2312");       
           byte[] temp=new byte[filedata.length+len];
           if (len==100)  //前面部分完整数据
           {
            for (int i=0;i<filedata.length;i++)
            {
             temp[i]=filedata[i];
            }
            for (int i=0;i<buf.length;i++)
            {
             temp[filedata.length+i]=buf[i];
            }
           }
           else    //前面部分完整数据
           {
            for (int i=0;i<filedata.length;i++)
            {
             temp[i]=filedata[i];
            }
            for (int i=0;i<len;i++)
            {
             temp[filedata.length+i]=buf[i];
            }
           }       
           filedata=temp;
          }
          try
          {
            if(is.available()>0)
            {
           len =is.read(buf);
            }
            else
            {
             len=-1;
            }
          }
          catch ( Exception e )
          {
           len=-1;
           e.printStackTrace( );
          }
         }
         try
         {
          String s=new String( filedata,"gb2312");
                BufferedWriter bw=new BufferedWriter(new FileWriter("update.xml"));

                   if (s!=null)
                   {
                    bw.write(s);            
                   }
                   bw.close();
          System.out.println("\nFile has been recerved successfully.");
         }
         catch ( Exception e )
         {
          System.out.println("\nfile save error.");
          e.printStackTrace( );
          os.write("update fail".getBytes( ));
         } 

         new update();
         //转换后传送给客户端
         os.write("update success".getBytes( ));

         break;     
        }
        
        

        if ( revStr.startsWith( "sim" ) )//表明客户端请求传输一个文件
        {     
         //fileName = getFileName(revStr );
         os.write("well".getBytes( ));     
         byte[] filedata=new byte[0];     
         len = is.read( buf );
         while (len!= -1)
         { 
          if (len>0)
          {       
           String str=new String( buf,"gb2312");       
           byte[] temp=new byte[filedata.length+len];
           if (len==100)  //前面部分完整数据
           {
            for (int i=0;i<filedata.length;i++)
            {
             temp[i]=filedata[i];
            }
            for (int i=0;i<buf.length;i++)
            {
             temp[filedata.length+i]=buf[i];
            }
           }
           else    //前面部分完整数据
           {
            for (int i=0;i<filedata.length;i++)
            {
             temp[i]=filedata[i];
            }
            for (int i=0;i<len;i++)
            {
             temp[filedata.length+i]=buf[i];
            }
           }       
           filedata=temp;
          }
          try
          {
            if(is.available()>0)
            {
           len =is.read(buf);
            }
            else
            {
             len=-1;
            }
          }
          catch ( Exception e )
          {
           len=-1;
           e.printStackTrace( );
          }
         }
         try
         {
          String s=new String( filedata,"gb2312");
                BufferedWriter bw=new BufferedWriter(new FileWriter("sim.xml"));

                   if (s!=null)
                   {
                    bw.write(s);            
                   }
                   bw.close();
          System.out.println("\nFile has been recerved successfully.");
         }
         catch ( Exception e )
         {
          System.out.println("\nfile save error.");
          e.printStackTrace( );
          os.write("update fail".getBytes( ));
         } 

         updatesim sim=new updatesim();
         //转换后传送给客户端
         os.write("update success".getBytes( ));

         break;     
        }         
        
       }

       os.close( );
       is.close( );
       s.close( );
      }
      catch ( Exception e )
      {
       e.printStackTrace( );
      }
     }
     
     private String getFileName( String revStr )
     {
      String fileName;
      int index=revStr.indexOf(":")+1;
      fileName = revStr.substring(index);
      return fileName;
     }

     public static void server()
     {
      System.out.println( "This is server" );
      
      try
      {
       ServerSocket ss = new ServerSocket( PORT );
       int count = 0;
       while ( true )
       {
        // 创建一个Socket等待客户端连接
        Socket s = ss.accept( );
        count++ ;
        System.out.println( "This is the " + count + "'st client connetion!" );
        new SendFileSocket( s ).start( );// 启动一个线程为这个客户端服务
       }
      } catch ( Exception ex )
      {
       ex.printStackTrace( );
      }
     }
     
     public String getowlfilename(String clientname)
     {
      String line=null; // 用来保存每行读取的内容
      String owlfilename=null;
      try
      {
       InputStream is = new FileInputStream("ontoclient.txt");
       BufferedReader reader = new BufferedReader(new InputStreamReader(is));    

       line = reader.readLine(); // 读取第一行

       while (line!=null)
       {
        String[] str=line.split("#");
        if (clientname.equals(str[0]))
        {
         owlfilename=str[1];
        }
        line = reader.readLine(); // 读取下一行  
       }
       
         }
         catch (Exception ex)
         {
          ex.printStackTrace();
         }   
      return  owlfilename;
     }
     
        public synchronized void startServer() //启动服务器
        {  
            this.running = true;
            //start();  //启动服务器线程
        }
        public synchronized void stopServer()
        {
            this.running = false;
            try
            {
                this.ss.close();
            }
            catch (IOException ex)
            {
                ex.printStackTrace();
            }
            //用socket虚假连接,跳过阻塞,结束进程
            Socket socket = null;
            try
            {
                socket = new Socket("127.0.0.1",PORT);      //!!!!!!!!!!!
            }
            catch (UnknownHostException ex)
            {
                ex.printStackTrace();
            }
            catch (IOException ex)
            {
                ex.printStackTrace();
            }
            try
            {
                socket.getOutputStream().write(1);
            }
            catch (IOException ex)
            {
                ex.printStackTrace();
            }
            try
            {
                socket.close();
            } catch (IOException ex)
            {
                ex.printStackTrace();
            }
            
        }  
     
    }

    /*
    class PrinterServer extends Thread
    {


        

        public static final int DEFFAULT_PORT = 8888;                                
                              
        private ServerSocket serverSocket;
        private int port;
        
        private volatile boolean running;  //服务器正在运行的标志
        
        public PrinterServer()
        {                      
            this(DEFFAULT_PORT);
        }
        public PrinterServer(int port)
        {
          
            try
            {
                if(port <= 0 || port > 0xFFFF)
                {
                    this.port = port;
                }
                serverSocket  = new ServerSocket(port);
                //设置超时值如果 accept 方法调用超过超时值将引发 java.net.SocketTimeoutException
      //          this.serverSocket.setSoTimeout(3000);
            }
            catch (IOException ex)
            {
                ex.printStackTrace();
            }
        }
        public synchronized void startServer() {  //启动服务器
            this.running = true;
            start();  //启动服务器线程
        }
        public synchronized void stopServer()
        {
            this.running = false;
            try
            {
                this.serverSocket.close();
            }
            catch (IOException ex)
            {
                ex.printStackTrace();
            }
            //用socket虚假连接,跳过阻塞,结束进程
            Socket socket = null;
            try
            {
                socket = new Socket("127.0.0.1",8888);      //!!!!!!!!!!!
            }
            catch (UnknownHostException ex)
            {
                ex.printStackTrace();
            }
            catch (IOException ex)
            {
                ex.printStackTrace();
            }
            try
            {
                socket.getOutputStream().write(1);
            }
            catch (IOException ex)
            {
                ex.printStackTrace();
            }
            try
            {
                socket.close();
            }
            catch (IOException ex)
            {
                ex.printStackTrace();
            }
            
        }


        public void run()
        {
            try
            {
                while(this.running)
                {
                    Socket socket = null;
                    try
                    {              
                        socket = serverSocket.accept();      
                    }
                    catch (SocketTimeoutException e)
                    {                
                        //e.printStackTrace();
                    }
                    if(socket!=null)
                    {
                          UserThread userThread = new UserThread(socket);
                          userThread.start();
                    }
                }
            }
            catch (IOException ex)
            {
                        System.out.println("The serverSocket stopping");
            }
        }
    }
    */


    可参考修改

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/10/25 15:42:00
     
     liuytliuyt 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(汇编考了97分!)
      文章:31
      积分:333
      门派:XML.ORG.CN
      注册:2007/9/18

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给liuytliuyt发送一个短消息 把liuytliuyt加入好友 查看liuytliuyt的个人资料 搜索liuytliuyt在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看liuytliuyt的博客8
    发贴心情 
    这里的代码你肯定通不过,因为少了很多文件,你也不能了解我的具体情况,但你可参考其Socket通信的思路,修改这段代码,可以实现c#与java的通信,从而在vs中操作本体
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/10/25 15:46:00
     
     liuytliuyt 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(汇编考了97分!)
      文章:31
      积分:333
      门派:XML.ORG.CN
      注册:2007/9/18

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给liuytliuyt发送一个短消息 把liuytliuyt加入好友 查看liuytliuyt的个人资料 搜索liuytliuyt在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看liuytliuyt的博客9
    发贴心情 
    c#端的另一端关键代码
    --------
            private void querysocket()
            {
                try
                {
                    int port =Form1.port;       
                    string host = Form1.host;
                    IPAddress ip = IPAddress.Parse(host);
                    IPEndPoint ipe = new IPEndPoint(ip, port);//把ip和端口转化为IPEndPoint实例

                    //发送查询文件,获取查询结果。
                    Socket c = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个Socket
                    c.Connect(ipe);//连接到服务器
                    string sendStr = "query";
                    byte[] bs = Encoding.Default.GetBytes(sendStr);
                    c.Send(bs, bs.Length, 0);//发送测试信息

                    NetworkStream ns = new NetworkStream(c);
                    FileStream fs = new FileStream(@"C:\test\queryresult.xml", FileMode.OpenOrCreate); //查询后的结果文件
                    byte[] receiveBuf = new byte[1024];
                    int count = ns.Read(receiveBuf, 0, receiveBuf.Length);

                    string back = System.Text.Encoding.Default.GetString(receiveBuf);
                    back = back.Substring(0, 4);
                    if (back == "well")
                    {
                        //发送需要查询的文件
       
                        StreamReader objReader = new StreamReader(@"C:\test\query.xml", System.Text.Encoding.Default);
                        string Line = "";
                        string newline;
                        newline = objReader.ReadLine();
                        while (newline != null)
                        {
                            string temp = newline;
                            newline = objReader.ReadLine();
                            if (newline != null)
                            {
                                Line = Line + temp;
                            }
                            else
                            {
                                Line = Line + temp;
                            }

                        }

                        byte[] b = Encoding.Default.GetBytes(Line);
                        c.Send(b, b.Length, 0);
                        objReader.Close();


                        //接受查询结果文件
                        bool isRead = true;
                        receiveBuf = new byte[1024];
                        while (isRead)
                        {
                            count = ns.Read(receiveBuf, 0, receiveBuf.Length);
                            if (count > 0 && count <= receiveBuf.Length)
                            {
                                isRead = true;
                                fs.Write(receiveBuf, 0, count);

                            }
                            else
                            {
                                isRead = false;
                            }

                        }

                        fs.Close();
                    }
                    c.Close();
                }
                catch (Exception e1)
                {
                    MessageBox.Show(e1.ToString());
                }
            }

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/10/25 15:48:00
     
     campbell 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:6
      积分:76
      门派:XML.ORG.CN
      注册:2010/10/9

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给campbell发送一个短消息 把campbell加入好友 查看campbell的个人资料 搜索campbell在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看campbell的博客10
    发贴心情 
    真的非常感谢你,我们回去研究一下,如果可以希望以后有可能还能得到你的帮助。祝天天开心!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/10/25 20:12:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/12/18 11:28:48

    本主题贴数11,分页: [1] [2]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    203.125ms