serversocket

What can cause “ IO error java.net.SocketException: select failed ”?

十年热恋 提交于 2019-12-06 03:39:44
I have a server program running on my laptop, same router and same code. It work's fine and clients can connect. However when I copied the workspace to my PC and when I run it, I get this nonsense: IO error java.net.SocketException: select failed Here is the code... public static void main(String[] args) { System.out.println("running server!"); int nreq = 1; try{ ServerSocket sock = new ServerSocket(7331); for(;;){ Socket newsock = sock.accept(); System.out.println("Creating thread..."); //Thread t = new ThreadHandler(newsock, nreq); //t.start(); nreq++; } } catch(Exception e) { System.out

Java Socket/Serversocket WAN Connection

对着背影说爱祢 提交于 2019-12-05 17:04:46
Im trying to make a server out of my computer so that clients from their computers can connect and communicate with my computer. I made the server on port 31350 and the client is trying to connect through my router's ip address. But it only works through lan when I have "localhost" or the name of my computer in the parameters for the socket creation. and not when I use my ip address, running the client and server on different networks. Here is the code. Here is the server that my computer is running. public static void main (String[] args) throws IOException { ServerSocket server = new

ServerSocket - Is it really necessary to close() it?

佐手、 提交于 2019-12-05 01:34:26
I have this damnable structure: public void run() { try { if (!portField.getText().equals("")) { String p = portField.getText(); CharSequence numbers = "0123456789"; btnRun.setEnabled(false); if (p.contains(numbers)) { ServerSocket listener = new ServerSocket(Integer.parseInt(p)); while (true) { Socket socket = listener.accept(); try { PrintWriter out = new PrintWriter(socket.getOutputStream(), true); out.println("Hi there, human."); } finally { socket.close(); } }} else { JOptionPane.showMessageDialog(null, "Only numbers are allowed."); } } } catch (NumberFormatException | HeadlessException |

Stopping a ServerSocket accept() loop thread

亡梦爱人 提交于 2019-12-04 20:11:44
I'm implementing a very basic API to have a better control over ServerSocket and Sockets, but I'm in a very weird problem that I cannot fix due to my lack of threads knowledge. Let me explain it. In my class SocketStreamReceiver I use a secondary thread to listen for new sockets with ServerSocket#accept() . There are 2 methods: start() and stop() that the client can use to start (creating a thread and begin listening with accept() ) and stop (closing the ServerSocket and destroying the thread) my SocketStreamReceiver. How will you implement stop() method? Keep in mind that stop() can be called

DataInputStream giving java.io.EOFException

為{幸葍}努か 提交于 2019-12-04 19:44:50
I have created small CLI client-server application. Once the server is loaded the client can connect to it and send commands to the server. The first command is to get list of files that server is loaded with. Once the socket connection is established. I request user to enter a command. ClientApp.java Socket client = new Socket(serverName, serverPort); Console c = System.console(); if (c == null) { System.err.println("No console!"); System.exit(1); } String command = c.readLine("Enter a command: "); OutputStream outToServer = client.getOutputStream(); DataOutputStream out = new

ServerSocket listens without accept()

你。 提交于 2019-12-04 15:46:43
I'm currently involved in a project at school in which we are building a communication system to be used on Android phones. For this, we will be using a server which opens sockets towards all clients, making them communicate. I've done several chat applications before without any problems with sockets or thread handling but this time, for some reason, it boogles my mind. The problem is that the application starts to listen as soon as I initiate the ServerSocket object, serverSocket = new ServerSocket(5000) , and not at the serverSocket.accept() . Why is that? As soon as I use the following

Server socket file transfer

我是研究僧i 提交于 2019-12-04 13:32:16
I have used server socket concept in java to transfer files like images and videos. But when i receive at the client side, i am customizing the file names. Can i get the original name of the file as it is? For Example: If the file from server end for transfer is "abc.txt", i need this same name to be reflected in the client end(without passing the name separately). In the server end: public class FileServer { public static void main (String [] args ) throws Exception { // create socket ServerSocket servsock = new ServerSocket(13267); while (true) { System.out.println("Waiting..."); Socket sock

Transfer a file between Android devices?

不羁岁月 提交于 2019-12-04 07:55:13
I'm making a code and I want to send a mp4 file to another Android device. I have reached to connect both Androids via Wifi and write from one a simple for cycle from 1-20 and the other Android device reads and displays the number that is sent. Here it is the interesting part of the "sender": InetAddress serverAddr = InetAddress.getByName(serverIpAddress); Log.d("ClientActivity", "C: Connecting..."); Socket socket = new Socket(serverAddr, port); connected = true; while (connected) { try { Log.d("ClientActivity", "C: Sending command."); PrintWriter out = new PrintWriter(new BufferedWriter(new

Listen for incoming connections in AS3 (AIR) Client whithout using Server Socket

↘锁芯ラ 提交于 2019-12-04 06:32:33
I managed to create a C# Server that sends files to AS3(AIR) Clients using sockets . On the AS3 side I'm using the flash.net.Socket library to receive the data through TCP . This is how it works: -> I turn on my server, and it listens for clients (plus I can create a list of connected devices); -> I turn on my client and it automatically receives the data; The trigger event to receive the data is made on the client, i.e., I simply turn the server ON and when the client turns ON, it gets the data, triggering these events: socket.addEventListener(Event.CONNECT, onConnect); -> to connect to the

I've created a Java server with sockets, just how do print to ALL sockets?

大城市里の小女人 提交于 2019-12-04 03:43:49
I've been trying this for a while, and I want multiple clients to recieve multiple inputs simultaneously. There is one problem, I want the server to print "Hi" to all clients if one client says 'print2all Hi'. I know how to process it to print it, just to print to ALL clients is the problem. Here's what I have so far. Server try{ try{ server = new ServerSocket(25565); } catch (Exception e){ e.printStackTrace(); } while (isListening){ new SocketThread(server.accept()).start(); } server.close(); } catch (Exception e){ e.printStackTrace(); } SocketThread try { PrintWriter out = new PrintWriter