serversocket

Java exception must be caught or declared to be thrown [duplicate]

主宰稳场 提交于 2019-12-25 04:35:18
问题 This question already has answers here : Java unreported exception (2 answers) Closed 3 years ago . I am trying to learn Java networking using this manual - http://duta.github.io/writing/StartingNetworking.pdf Why do I get “must be caught or declared to be thrown” at this line (it is ServerSocket part of the manual). Why the code in the manual is assumed to be working, but mine doesn't? Socket socket = serverSocket.accept(); Complete code: public class ChatServer { public static void main(){

HashMap data not appending new data into ArrayList

╄→尐↘猪︶ㄣ 提交于 2019-12-25 02:38:17
问题 I am using the following code to connect with java socket from an Applet client. I store Client's IP Address and some random number in every NEW connection happening in addNewClient() function in the below code. I store this info in HashMap . I add more client info in the ArrayList of this HashMap . If there is already some client info in ArrayList , I need to read through it. I am trying that in SocketConnection class below using Iterator . The problem I see is, I am adding some 3 client

Java Socket Programing

一个人想着一个人 提交于 2019-12-24 10:46:57
问题 Problem: I have written one java socket server which send response when I send first message from the client to it. But I want to send one more message based on the first response. After the first response i am not getting any other response? Here is the Server code: public class SendSmsServerSocket { private final static CxpsLogger logger = CxpsLogger.getLogger(SendSmsServerSocket.class); SendSmsServerSocket(){ try { new SeverSocketForSms(new ServerSocket(4330)); } catch (IOException e) { e

Compile javacode out of a running java accpilaction - on a system that hasn't JDK installed

99封情书 提交于 2019-12-24 09:57:28
问题 I'm currently writing on a tool that is client server based. Because of unstable IP-Adresses, my idea is to let the server-Application compile a client-application with the right IP of the server. Step-by-step: The serverapplication starts. The user looks, what current IP his server-computer has (this can be done manually over a webbrowser). With this IP he creates (compiles) a client which search a connection to this IP (once started). To make this possible, it's necessary to compile the

How to Bind a TServerSocket to a specific IP address

本秂侑毒 提交于 2019-12-24 05:52:00
问题 Does any one know any way to bind a Delphi TServerSocket component to accept requests only on a specific local address? The server has several IPs but it is requires that server application to accept requests on one IP only when its running. 回答1: TServerSocket does not directly expose the feature you are asking for, however it is doable with a little workaround. You need to derive a new class from TServerSocket in order to gain access to the protected TAbstractSocket.Address property. That is

Java poll on network connections

倾然丶 夕夏残阳落幕 提交于 2019-12-23 19:34:10
问题 I am writing a program in Java where I have opened 256 network connections on one thread. Whenever there is any data on a socket, I should read it and process the same. Currently, I am using the following approach : while true do iterate over all network connections do if non-blocking read on socket says there is data then read data process it endif done sleep for 10 milli-seconds done Is there a better way to do the same on Java ?? I know there is a poll method in C/C++. But after googling

Socket Exception: socket is closed [duplicate]

吃可爱长大的小学妹 提交于 2019-12-23 13:08:40
问题 This question already has an answer here : java.net.SocketException socket is closed (1 answer) Closed 2 years ago . I want to create server which is able to be connected with multiple clients. My main function is: ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(5556); } catch (IOException ex) { Logger.getLogger(MakaoServer.class.getName()).log(Level.SEVERE, null, ex); } while (true) { try { Socket connection = serverSocket.accept(); PlayerConnection playerConn = new

How can I bind serversocket to specific IP?

只愿长相守 提交于 2019-12-23 07:47:27
问题 If I have a String representing an IP address (IPv4 or IPv6) how can I create a ServerSocket and bind to this IP without caring if the IP passed in, is IPv4 or IPv6? I see that there is a constructor: ServerSocket(int port, int backlog, InetAddress bindAddr) but InetAddress does not seem to offer any constructors and its subclasses have names specific to IPv4 and IPv6. So how can I bind the socket to the IP? 回答1: You can use the factory method INetAddress.getByName. It'll figure out which

Socket Backlog behaviour

浪子不回头ぞ 提交于 2019-12-23 02:52:38
问题 In case of a Serversocket have full of request in its backlog and doing a long running job what will be the socket behaviour. When I try this, from windows telnet is ok, it connects. But from unix it gets "connection refused" . My application is written in java and running on IBM jvm . By the way I came to that point where our application was not responding telnet from unix. Not respoing means it was writing "tyring..." and hangs, not refusing or connecting. Can anybody justify this behavior?

Java - connection to ServerSocket via browser/URL

≯℡__Kan透↙ 提交于 2019-12-22 18:37:27
问题 I'm writing a piece of software, and I'm under the restriction of not being able to use socket to connect to a java application using a ServerSocket. I thought I'd try with an URL connection, since it's possible to define which port to connect to e.g: 127.0.0.1:62666 I have my server app listening for connections and writing the input out to a jTextArea. When connecting to the server (127.0.0.1:62666) through a browser, it outputs: GET / HTTP/1.1 GET /favicon.ico HTTP/1.1 I have another app