开发者

Ubuntu - UnknownHostException when connecting to a PC, using a Socket in an Ad Hoc network

开发者 https://www.devze.com 2023-02-23 11:30 出处:网络
I have created a FileSystemListener that listens for files in a folder and sends them to a specified IP address. This has all been tested with a standard wireless network but I am getting an unkownhos

I have created a FileSystemListener that listens for files in a folder and sends them to a specified IP address. This has all been tested with a standard wireless network but I am getting an unkownhostexception when running it on an ad hoc network.

I was not sure if this was something I should ask on Superuser, or here, as I am not sure if it is an issue with my code or Ubuntu.

I can ping the other PC on the wireless network but I keep getting the above exception when connecting through java.

Not sure if it helps but here is the most basic SSCE I can think of:

import java.net.Socket;

public class ClientTester {

  public static void main(String[] args) {
        Socket s  = new Socket("192.168.0.1", 4440);
   }
}

Anyone come across this before, wanted to see if it was a Java issue before I cr开发者_开发知识库oss posted in Superuser.

Thanks!


To compile correctly, UnknownHostException "must be caught or declared to be thrown."

For example:

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientTester {

    public static void main(String[] args)
        throws UnknownHostException, IOException {
        Socket s  = new Socket("192.168.0.1", 4440);
   }

}


If this works with regular infrastructure mode, but not with ad-hoc mode you probably haven't configured the ad-hoc mode properly. Could you show us your /etc/network/interfaces config?

0

精彩评论

暂无评论...
验证码 换一张
取 消