客户端重新连接java套接字

好吧,我需要编写一个能够检测客户端和服务器之间连接的客户端…一旦服务器关闭并恢复我的客户端需要能够将其连接回服务器..但我真的不是确定如何做…如果可能的话,任何帮助? public TEST(String serverIP, int serverPort){ Log(“Connection to the Server….”); try{ socket = new Socket(serverIP, serverPort); Log(“Connected to the server : “+socket); start(); } catch(UnknownHostException uhe){ System.out.println(“Unknown Host: “+ uhe.getMessage()); } catch (IOException ioe){ System.out.println(“IO Exception: “+ioe.getMessage()); } String readline = “”; streamOutput.println(“TRY test”); while(true){ try{ readline = streamInput.readLine(); System.out.println(readline); } catch (IOException ioe){ System.out.println(“Error […]

如何在命令行中运行包含OpenCV代码并使用ant创建的.jar文件?

我试图从Ubuntu控制台运行一个小的java类,它包含这样的OpenCV代码: import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.CvType; import org.opencv.core.Scalar; class SimpleSample { static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } public static void main(String[] args) { System.out.println(“Welcome to OpenCV ” + Core.VERSION); Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0)); System.out.println(“OpenCV Mat: ” + m); Mat mr1 = m.row(1); mr1.setTo(new Scalar(1)); Mat mc5 = m.col(5); mc5.setTo(new Scalar(5)); System.out.println(“OpenCV Mat […]

你如何在一个圆形的int数组上执行左移?

是否存在在圆形的int数组上执行左移的现有方法? 具体来说,给定一个包含4个项{1,2,3,4}并且移位量为2的数组,我想要一个方法将前两个字母移动到数组的后面,使它看起来像这样: {3,4,1,2} 。 这个算法是否可以将圆形数组移动一个? algShiftByOne(Array) { temp=array[0]; i=1 while(i < Array.length – 1) // Loop from 1 up to array.length == last index { // If there is no exception i assume it copies value from // initial array starting from 1 up to array.length Array[i – 1] = Array[i]; i++; } Array[Array.length]=temp; }

运行一个jar子两次

可以两次运行Jar吗? 例如,考虑一个有2个入口点的Jar。 我可以同时运行它们两次,每次都有一个条目, 没有任何奇怪的(如内存)问题 ?

字符串中的子串数

我的程序应该执行以下操作: 用户输入一个字符串:科迪勒拉斯大学 用户输入子字符串:er 程序输出substring-count:2(Cordill er的大学) 我不应该使用.str,而是创建我自己的方法。

从jar子里取出txt并卡住

我目前开始编写一个可以加载不同游戏的棋盘游戏。 我将这些游戏存储在名为config.txt的文件中,但是我无法访问它。 首先,我从我最喜欢的文件方法开始: String fileAddress = “./resources/config.txt”; fis = new FileInputStream(fileAddress); reader = new BufferedReader(new InputStreamReader(fis)); 但是当我构建.jar文件时,它停止了工作。 原因很明显。 所以我发现自己环顾四周,发现了使用getResourceAsStream(String s)方法的建议。 所以我将代码更改为以下方式: String fileAddress = “./resources/config.txt”; InputStream toReturn=null; toReturn = this.getClass().getClassLoader().getResourceAsStream(fileAddress); 但在这里我被困住了。 无论我如何调整fileAddress(尝试./config.txt ./resources/config.txt ./resources/boardgames/config.txt和./resources/boardgames/config.txt)以及使用或省略getClassLoader(), toReturn的结果总是等于NULL并最终很快抛出NullPointerException。 所需文件的位置如下。 由于我没有足够的声誉,我将不得不将ASCII艺术作为文件层次结构。 config.txt都是有效的目标。 在文件系统上: Boardgames src cache classes resources boardgames config.txt imgs config.txt 在Jar文件里面 BoardGames.jar boardgames config.txt imgs META-INF config.txt […]

JPA spring boot内部join – with-clause引用了两个不同的from-clause元素错误

我正在尝试在我的一个JPA存储库中选择内部联接 查询: @Query(value = “select wm.WagerIdentification, wm.BoardNumber, wm.MarkSequenceNumber, wm.MarkNumber,” + ” pt.CouponTypeIdentification, pt.WagerBoardQuickPickMarksBoard ” + “from WagerBoard wb ” + “inner join wb.listOfWagerMarks wm on wb.WagerIdentification = wm.WagerIdentification and wb.BoardNumber = wm.BoardNumber and wb.GameIdentification = wm.GameIdentification and wm.meta_IsCurrent = 1 ” + “inner join wb.poolgameTransaction pt on (wb.TransactionIdentification = pt.TransactionIdentification and pt.meta_IsCurrent = 1)” + […]

将JButton的多个实例添加到网格中的JFrame

下面的代码应该为我想要在网格中表示的特定类型(比如颜色)JButton创建和对象实例。 当我遍历for循环以将按钮添加到jframe时,它什么都没有添加。 但是,如果我添加一个实例变量,它将添加它。 有人有想法吗? public class Grid { protected JButton [][] board; private JButton player; private JButton openCell; private JButton wall; private JButton closedCell; public Grid(String [] args) { // args unused // Instantiation board = new JButton [6][6]; layout = new String [6][6]; blueCell = new JButton(“BLUE CELL”); redCell = new JButton(“RED CELL”); greenCell […]

使用多字元素搜索JComboBoxes

例如,假设我有一个带有元素{“example 1”,“example 2”,“example 3”}的JComboBox (请注意示例和相应数字之间的空格)。 当您在选择combobox时尝试通过键入搜索“示例2”时,它会关闭,因为空格键会切换组件的弹出窗口。 这可以分为两个问题: 我做了一个swing事件,到目前为止它识别出空格键,我已经禁用了JComboBox的默认空格键动作。 如何制作它以便按空格键实际上会使其添加到搜索中? 如果#1不可能或未知,还有什么方法可以做到这一点? 任何能够正确回答这个问题的人都绝对会收到一个upvote。

带有#in order by子句的ibatis内联参数

下面是我的ibatis地图配置, select * from contact salary like ‘%’ order by #orderby#, #orderby2# 这是我的pojo package com.nik; public class Contact { private String firstName; private String lastName; private String email; private String salary; private String mobile; private String orderby; private String orderby2; private int id; public Contact() {} public Contact( String firstName, String lastName, String email) { […]