serversocket

Java Server Socket Response

女生的网名这么多〃 提交于 2019-12-22 06:15:11
问题 I'm trying to create a simple client/server socket communication application (chat client). I've spent countless hours looking on how to fix this with still no luck, I can send the message to the server but I'm stuck with sending the message back from the server to the client. I believe the issue is how I'm getting the message from the server after it's sent back, I deleted what I had which was an InputStreamReader which I couldn't get to work. (I apologize in advance for the sloppy code)

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

半腔热情 提交于 2019-12-22 03:48:38
问题 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

Stopping a ServerSocket accept() loop thread

喜你入骨 提交于 2019-12-22 00:24:26
问题 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

get data from client in server socket java

家住魔仙堡 提交于 2019-12-21 21:21:12
问题 I am creating a server app which does the following task Accept connection from client Process each client connection to separate thread Receive data from client send data to client I am able to connect client but not able to receive data from client Data is being visible in my console only when THAT CLIENT GETS DISCONNECTED..!!! Code :- public class ServerListener { public static void main(String[] args) { new ServerListener().startServer(); } public void startServer() { final

ServerSocket + client Socket - how do I get IP address of client?

余生颓废 提交于 2019-12-21 16:59:42
问题 I have a ServerSocket instance which is listening for connections. When a client connects to it, I would like to get the IP of the connected socket, but can't seem to find the right method to do so. public void start() { listenSocket = new ServerSocket(port); connectionSocket = listenSocket.accept(); } I've tried calling the following with no luck: connectionSocket.getLocalAddress(); connectionSocket.getInetAddress.getHostAddress(); listenSocket.getLocalSocketAddress(); None of the above

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

左心房为你撑大大i 提交于 2019-12-21 16:57:49
问题 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

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

…衆ロ難τιáo~ 提交于 2019-12-21 12:03:19
问题 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()

Unsecured Bluetooth connection in Android

久未见 提交于 2019-12-21 05:03:35
问题 I have been challenged by a professor to develop a little Bluetooth Demo app on Android. I knew nothing about developping for Android until 2 weeks ago when he gave me that challenge. I'm also quite new at Java programming in general, so I'm starting from far. But anyway... So I did most of the tutorial, and I read about Bluetooth in Android, looked at the Bluetooth Chat sample code, and I'm now trying to do my little app. So for my demo, I will try to establish a connection between my real

When hitting a JButton to connect to a server , the program freezes

ぐ巨炮叔叔 提交于 2019-12-20 07:38:32
问题 I am making a simple 1v1 "private chat" using TCP in java. Currently, i have a problem whenever i am using JButtons. This is my first attempt at using JButtons and ActionListeners so i'm not 100% sure whats going on here. I have two separate projects for the Server and the Client. To compile these, it would have to be two separate projects. The problem occurs when i try to hit the button to either A: Start the server B: Connect to the server. The button freezes as if it is in the pushed state

Application hangs when attempting to retrieve text from an inputstream

无人久伴 提交于 2019-12-20 05:47:19
问题 Situation I've been creating a program to exchange messages between two computers in the LAN. One computer identifies itself as the server while the other is a client. Upon startup, the user has to enter the Host and the Port of another computer, should he wish to connect as a client to that machine. The setup of how it works is very basic: You type your message, hit enter and it shows up on your own screen. After that your conversation partner has to click a button to retrieve the latest