serversocket

How to get input from server console in a client server program

北城以北 提交于 2019-12-10 16:19:40
问题 I have implemented a customer interface using java (multithreaded). On the client side customer logs in when the server is already running. Multiple clients can login creating a thread for each client. What I want to achieve is when multiple clients are logged in I want to enter a command in server console(eclipse) that lists all the clients logged in after i input something on console. ClientSide of the code: btnLogin.addActionListener(new ActionListener() { @Override public void

Socket.Shutdown throws SocketException

被刻印的时光 ゝ 提交于 2019-12-10 13:58:03
问题 I'm trying to implement async sockets for my project. Here's the code public void Start(int listeningPort) { var ipHostInfo = Dns.Resolve(Dns.GetHostName()); var ipAddress = ipHostInfo.AddressList[0]; var localEndPoint = new IPEndPoint(ipAddress, listeningPort); _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _listener.Bind(localEndPoint); _listener.Listen(3000); Started = true; Task.Factory.StartNew(() => { while (Started) { allDone.Reset(); _listener

Is calling ServerSocket.close() sufficient enough to close a port?

戏子无情 提交于 2019-12-10 11:40:25
问题 I have some java code that looks similar to this: private void startServer() throws IOException { URLClassLoader classloader = null; System.out.println("Opening server socket for listening on " + PORT_NUMBER); try { server = new ServerSocket(PORT_NUMBER); server.setSoTimeout(10000); connected = true; System.out.println("Server is now listening on port " + PORT_NUMBER); } catch (IOException e) { System.err.println("Could not start server on port " + PORT_NUMBER); e.printStackTrace(); connected

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

空扰寡人 提交于 2019-12-10 10:21:05
问题 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..."); /

Android Machine is not on the network

我们两清 提交于 2019-12-09 14:58:25
问题 I am having a problem Running a network service when my app connects to a WiFi network. I am getting a the following exception, java.net.SocketException: socket failed: ENONET (Machine is not on the network) in the openPort() method bellow BroadcastReceiver @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA

Sending an ArrayList<String> from the server side to the client side over TCP using socket? [closed]

与世无争的帅哥 提交于 2019-12-09 10:51:32
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm trying to send one object from the server side socket to the client side socket over TCP. I can't find out where is the problem. Here is the error I'm getting on the Client side: java.io.EOFException at java

File upload using ServerSocket & HTML Client. Stuck at InputStream.read()

落爺英雄遲暮 提交于 2019-12-08 10:28:30
问题 To understand the concept of socket programming, I created a server and a client. The client will send a file and server should save it some location. (ie. a file upload). Server: package com.test.socket.server; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; public class WebServer { public static void main(String[] args) throws IOException { ServerSocket serverSocket =

Java ServerSocket required for UDP communication?

丶灬走出姿态 提交于 2019-12-08 09:34:57
问题 I had following question on the exam: "Let us assume that you want to use UDP for a client. Do you need to create a new socket for managing parallel connections in UDP? Why or why not? What happens if multiple clients connect to that socket?" The question also referenced a Java class TCPServer.java , which creates ServerSocket and later on in a while(true) loop, it accepts connections and creates Sockets for incoming connection requests from users. To my mind, TCP Server is only used for TCP

Android socket connect in background

孤者浪人 提交于 2019-12-08 05:14:04
问题 What should I do to keep the server running and listening when the application is in the background? I'm currently throwing an error: I can't make a connection because the target computer is actively refusing to connect. I have server on android and client on pc/python. anyone could explain I will be grateful. Code with my server. public class MainActivity extends Activity { private ServerSocket serverSocket; Handler updateConversationHandler; Thread serverThread = null; private TextView text

Server socket - accept connections only from IP addresses in the whitelist

依然范特西╮ 提交于 2019-12-08 04:28:06
问题 I have a socket server that listens and accepts connections from client, which works as follow: ... do some pre-processing (socket, binds, etc) //listen to client if (listen(sockfd, BACKLOG) == -1) { perror("listen"); exit(1); } printf("server: waiting for connections...\n"); while(1) { // main accept() loop sin_size = sizeof client_addr; new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size); if (new_fd == -1) { perror("accept"); continue; } //do something ..... ..... } How can I