serversocket

Application hangs when attempting to retrieve text from an inputstream

谁说胖子不能爱 提交于 2019-12-02 11:23:34
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 messages and it should show up on his screen. This goes on untill someone leaves. Problem The program

Broadcasting packet to client not working in java

纵饮孤独 提交于 2019-12-02 10:57:21
I have multiple transmitters configured to send back a response when they receive a broadcast packet sent from a server through local port 5255, remote port 5252 containing the string "AST show me\0" (as stated in transmitters' manual). This should help me to scan for all the transmitters within the local network. I have implemented a server side code to broadcast that string message, but when I run the code , it have a bug at the following line code : socket.receive(packet1); I don't really know what I am doing wrong or missing in this code. Any help will be greatly appreciated. Note: If it

Writing messages to client socket using DataOutputStream to Server Socket only sent after closing the Client Socket why?

允我心安 提交于 2019-12-02 03:58:21
问题 I had a Socket-Client programming in Java . I am using DataOutputStream to send messages to the Server Socket . Sometimes writed messages on DataOutputstream was not sent to the ServerSocket . I think it's due to i am not flushing after sent message . I do this but no use . If I terminate the class execution then only I receive messages from ServerSocket . My CODE : public class LoggingClient { LinkedBlockingQueue<byte[]> messages = new LinkedBlockingQueue<byte[]>(); public static

Writing messages to client socket using DataOutputStream to Server Socket only sent after closing the Client Socket why?

南楼画角 提交于 2019-12-02 01:03:05
I had a Socket-Client programming in Java . I am using DataOutputStream to send messages to the Server Socket . Sometimes writed messages on DataOutputstream was not sent to the ServerSocket . I think it's due to i am not flushing after sent message . I do this but no use . If I terminate the class execution then only I receive messages from ServerSocket . My CODE : public class LoggingClient { LinkedBlockingQueue<byte[]> messages = new LinkedBlockingQueue<byte[]>(); public static LoggingClient clientObj; /* * waiting 2 seconds for connecting centralized log server . If it's not reachable

Java socket EOFException

半世苍凉 提交于 2019-12-01 15:31:08
I use RMI and socket to transfer files between a client set. The problem is when running the code below sometimes i get this exception in client side : java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2671) at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3146) at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:858) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:354) at javafxcyberwind.serverSocket.run(serverSocket.java:38) at java.lang.Thread.run(Thread.java:748) This is a sample

Java socket EOFException

会有一股神秘感。 提交于 2019-12-01 13:34:11
问题 I use RMI and socket to transfer files between a client set. The problem is when running the code below sometimes i get this exception in client side : java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2671) at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3146) at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:858) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:354) at

Java the difference of Socket and ServerSocket in using port

不问归期 提交于 2019-12-01 06:28:41
At the server side, we use Socket server = serverSocket.accept(); to create a socket. After the socket is created, we can create a new thread to handle the input/output stream of that socket. So we can go back to listening at the same port and create new socket if there are further connection requests come in. Since we already created ServerSocket at a specific port, of course we could not create another ServerSocket at that port again. So from my understanding, can I conclude that, at server side, we can create multiple sockets under one port? (similar to what web server does) Actually my

How to close port after using server sockets [closed]

↘锁芯ラ 提交于 2019-12-01 06:11:01
In my application I create a ServerSocket instance with some port. After I am finished, I close the socket, but when I try to make a new ServerSocket on the same port, it throws: "java.net.BindException: Address already in use" If I create the ServerSocket with a different port, then it works. ServerSocket.isClosed also returns true What is the problem? public void run() { try { BufferedInputStream bufferedinputstream = new BufferedInputStream( new FileInputStream(fileReq)); BufferedOutputStream outStream = new BufferedOutputStream( cs.getOutputStream()); byte buffer[] = new byte[1024]; int

Usage of getaddrinfo() with AI_PASSIVE

强颜欢笑 提交于 2019-12-01 05:16:23
The getaddrinfo() function not only allows for client programs to efficiently find the correct data for creating a socket to a given host, it also allows for servers to bind to the correct socket - in theory. I just learned about that and started to play around with it via Python: from socket import * for i in getaddrinfo(None, 22, AF_UNSPEC, SOCK_STREAM, IPPROTO_IP, AI_PASSIVE): i yields (2, 1, 6, '', ('0.0.0.0', 22)) (10, 1, 6, '', ('::', 22, 0, 0)) what makes me wonder about if there is something wrong. What exactly am I supposed to do with these answers? Should I make a listen() ing socket

Java the difference of Socket and ServerSocket in using port

点点圈 提交于 2019-12-01 04:25:36
问题 At the server side, we use Socket server = serverSocket.accept(); to create a socket. After the socket is created, we can create a new thread to handle the input/output stream of that socket. So we can go back to listening at the same port and create new socket if there are further connection requests come in. Since we already created ServerSocket at a specific port, of course we could not create another ServerSocket at that port again. So from my understanding, can I conclude that, at server