serversocket

how do i connect to the server socket using the ip address and port number( client is running on a different machine than server)

陌路散爱 提交于 2019-11-29 08:05:15
Client program public class client implements Runnable { protected static String server_IP = "141.117.57.42"; private static final int server_Port = 5555 ; protected static String client_IP ; public static void main(String[] args) throws IOException{ final String host = "localhost"; int init = 0 ; try { InetAddress iAddress = InetAddress.getLocalHost(); client_IP = iAddress.getHostAddress(); System.out.println("Current IP address : " +client_IP); } catch (UnknownHostException e) { } try {System.out.println("hello1"); Socket socket = new Socket(server_IP,server_Port); System.out.println("hello3

Reading POST data from html form sent to serversocket

我是研究僧i 提交于 2019-11-29 02:20:58
i try to write simplest possible server app in Java, displaying html form with textarea input, which after submitting gives me possibility to parse xml typed in that textarea. For now i build simple serversocket based server like that: import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class WebServer { protected void start() { ServerSocket s; String gets = ""; System.out.println("Start on port 80"); try { // create the main server socket s = new ServerSocket(80); } catch (Exception e) {

Server-Client chat program

风流意气都作罢 提交于 2019-11-28 14:05:33
问题 I am writing a server-client chat program. Here is my code SERVER: import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; public class HelloServer { public final static int defaultPort = 2345; public static void main(String[] args) { int port = defaultPort; try { port = Integer.parseInt(args[0]); } catch (Exception e) { } if (port <= 0 || port >= 65536) { port = defaultPort; } try { ServerSocket ss = new

Knock Knock application with server and UI

放肆的年华 提交于 2019-11-28 12:31:32
问题 I am creating a simple Knock Knock application (socket programming) where there is a localhost server and there is a client.the program is simple, the server will tell the knock knock jokes, this is how it's supposed to go, Server: Knock Knock Client: Who's there? Server: Turnip. Client: Turnip Who? Server: Turnip the heat. So that's how the program supposed to go. but the thing is my GUI doesn't show any messages. on my Text area. Here are my codes. The Server: import java.net.*; import java

Error message: “Bitmap Image is not valid” on received from Socket

元气小坏坏 提交于 2019-11-28 12:27:41
问题 I'm trying to get a screenshot and send it over the web using ClientSocket and ServerSocket components. I'm having problems when I try to turn the stream received at ServerSocket into a picture again. Error message "Bitmap Image is not valid!" when performing: DesktopForm.imgScreen.Picture.Bitmap.LoadFromStream(ms); I do not know if the problem is in the way sending the image or get in the way. My server code: unit UntThreadDesktop; interface uses System.Classes, System.SysUtils, System.Win

Send message from a basic server to a specific client

心已入冬 提交于 2019-11-28 11:43:32
I have two wifi modules M1 and M2 that connect to my access point. I have an android phone that connects to the same access point. I have a socket server on my android phone and the two modules join to the server as clients. Now my question is, is it possible to send a string message from my phone to module M1 without having to send anything to M2. I want to choose between clients to send the message to. Is it even possible in Java? Ok, here goes. //setting up server ServerSocket serverSocket = new ServerSocket(8000, 0, IPaddress); //creating a client socket to accept it Socket clientSocket =

Java ServerSocket connection limit?

喜你入骨 提交于 2019-11-28 11:06:12
I was running a few tests with sockets, and I encountered some strange behavior: A ServerSocket will refuse connections after the 50th client Socket connects to it, even if that client socket is closed before the next one is opened, and even if a delay is added between connections. The following program is my experimental code, which in its current state, throws no exceptions and terminates normally. However, if the array size of Socket[] clients is increased beyond 50, any client sockets attempting to connect after the 50th connection are refused by the server socket. Question: Why is 50 the

Java Server - Multiple ports?

不想你离开。 提交于 2019-11-27 23:01:40
I'm about to program a server but am wondering if what I have in mind is possible. My program will be outputting to multiple clients on multiple ports - each port can be accessed by multiple clients. Normally I would use a threaded socket server, but in this case I need it working for multiple ports. The usage I have in mind is in a vague pseudocode below: Start server Listen for incoming connections on several ports Identify the port being connected to If port 1, start a thread listening to client and outputting message type x If port 2, start a thread listening to client and outputting

Creating the ServerSocket in a separate thread?

守給你的承諾、 提交于 2019-11-27 18:11:38
I have a problem with using a ServerSocket in my application. I'm creating the ServerSocket in the constructor of my application. The constructor of the socket calls the accept() method to wait for a client to connect. The problem is that the accept() method is freezing my whole application until a client connects. So I would like to ask if there's an alternative to creating the whole ServerSocket in a separate thread, that the constructor of the ServerSocket and its accept() method is called beside my main application? Edit: Thanks to Olivier for the advice, putting the .accept into a

Reading POST data from html form sent to serversocket

倾然丶 夕夏残阳落幕 提交于 2019-11-27 16:40:38
问题 i try to write simplest possible server app in Java, displaying html form with textarea input, which after submitting gives me possibility to parse xml typed in that textarea. For now i build simple serversocket based server like that: import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class WebServer { protected void start() { ServerSocket s; String gets = ""; System.out.println("Start on