Unsigned Chars Over UDP Socket
May 22, 2014
I can have up to 100,000 simultaneous connections to a udp socket, which needs to be handled by separate threads. Each of the connections talk to a c program on an embedded device that sends and responds with an array of unsigned chars. Now Java does not have an unsigned char type. The closest you can use is a short. But DatagramPacket requires a byte argument:
public class Socket {
public Socket(int port) throws IOException {
new SocketThread().start();
} }
public class SocketThread extends Thread {
protected DatagramSocket socket = null;
[Code] .....
So how can I go about reading and writing unsigned chars over a udp socket?
View Replies
ADVERTISEMENT
Apr 10, 2015
I'm deploying Java 8 update 40 to my users and want to know if there's a way to manage sites that prompt the user with warnings about untrusted and unsigned applets?
i'm using the exception.sites file to manage applicable prompts/warnings for our internal sites, but doesn't look like the exception list works for untrusted and unsigned.
is there a way to manage these from an all users level, particularly with a deployment (ie, SCCM)?
View Replies
View Related
May 28, 2014
here I have a do-while loop. When I push a button, then press enter, the program should do stuff, then ask me for another key. If I press any key but q, it repeats itself. If I press q then enter, it should end the loop. But then when I press q then enter, it still does the functions in the do-while loop.
Java Code:
Scanner kb = new Scanner(System.in);
System.out.print("Press any key to start.");
String letter = kb.next();
do
{
stuff
System.out.print("Press any key to call another number or press "q" to quit.");
letter = kb.next();
}while(!letter.equals("q") || !letter.equals("Q")); mh_sh_highlight_all('java');
View Replies
View Related
Feb 8, 2015
For one of my homework questions, it asks us to: "Write a program that takes 2 strings, one that is the alphabet and the other that is a word, and displays the index value in string1 where the 1st character of the word appears."
So, I made the two strings. I turned the alphabet string into a string array. Now, I am completely lost as to how to call ints index value.
public class Alphabet{
public static void main(String[] args){
String [] Alphabet={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","z","w","x","y","z"};
String word="excalibur";
View Replies
View Related
Nov 27, 2014
I am working on a personal project and want to create a text editor to write my code. I am wondering how could I read the last input from the user and if say it was an open curly brace {, then like netbean's my editor will supply the closing curly brace. My java experience is limited but I have tried to read key board input and a few other options that did not work.
View Replies
View Related
Feb 13, 2014
I'm developing a web-based chatting system using JSP and socket.
The problem i am facing is that the sender can send message but on the receiver side we have to manually refresh the page. The sender stays into blocking mode until the receiver refresh its page !
after that i've implemented auto-refresh on the receiver side and "Connection Refused" exception is generated.
View Replies
View Related
Mar 4, 2014
Currently I have socket of the tcp version.
Java Code:
final ServerSocket serverSocketConn = new ServerSocket(9000);
while (true) {
try {
Socket socketConn1 = serverSocketConn.accept();
new Thread(new ConnectionHandler(socketConn1)).start();
[Code] .....
I managed to convert this final DatagramSocket serverSocketConn = new DatagramSocket (9000);
Now I am stuck here
Socket socketConn1 = serverSocketConn.accept();
new Thread(new ConnectionHandler(socketConn1)).start();
Can I use this or I need to create a manual thread pooling for UDP ?
View Replies
View Related
Apr 4, 2015
if i send messages as in the code below, is there a way to read only one message, if the client doesn't know how long it is (or if he only knows the maximum length)?in the documentation it says, that the method read(byte[]) reads until no data ist available or end of file is decteted. What does the latter mean? Can i extend the array that i sent by a byte that signals the end? Here is my Code:
Server
public class Server implements Runnable{
ServerSocket server;
HashMap<Short,Socket> clients;
public Server(){
clients = new HashMap<>();
[code]....
Both are startet in seperate threads. At the moment the first output of the client is "12 bytes read", and then continously "-1 bytes read"(because the server closes).
View Replies
View Related
Feb 10, 2014
I have been working with socket programming. I was trying to develop a two way communication from server to client. The data is being received when sent from server to client but there is a problem when I am sending from client to server.
I am getting an error as "Socket is closed" pointing to the line where I have created a BufferedReader. I have simplified some part of my code to be very specific.
Code attached.
import java.io.*;
import java.net.*;
import java.util.*;
public class Server
{
public static void main(String args[])
{
String id="policeone";
int hashcodeid=0;
[Code] ....
Error::
Receiving string from client: 'java.net.SocketException: Socket is closed
at java.net.Socket.getInputStream(Socket.java:872)
at Server.main(Server.java:51)
View Replies
View Related
Sep 21, 2014
I want to download objects (css , jpeg, html ,png ) using sockets in java without using httpurlconnection . How can i do this with simple socket library ?
View Replies
View Related
May 13, 2014
I got the below exception .how to resolve this .It's receiving the data up to 10 min then suddenly below error happening. I have embedded the source code below
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
[Code] .....
View Replies
View Related
Feb 13, 2014
I am new to JSP !! and I'm developing a web-based chatting system using JSP and socket.
The problem I am facing is that the sender can send message but on the receiver side we have to manually refresh the page. The sender stays into blocking mode until the receiver refresh its page !
After that I've implemented auto-refresh on the receiver side and "Connection Refused" exception is generated.
View Replies
View Related
Sep 26, 2014
I am trying to download object thorugh sockets in java . My code is
String servername = "http://ea-cdn.voxmedia.com"; //(String) innObj.get("value");
String filename = "http://ea-cdn.voxmedia.com/production/vox-40-maps/stylesheets/styles-358f0375.css"; //(String) request.get("url");
Socket socket = new Socket("http://10.10.78.62", 3128);
DataOutputStream bw = new DataOutputStream(
[code]...
View Replies
View Related
Jul 22, 2014
So we have a Client and Server. Client opens a socket to Server, server initiates new Thread to handle the communication with client. Is there a way to be singnalled when there is input on socket, so I don't have to use infinite while loop solution?
View Replies
View Related
Sep 2, 2014
i was reading my book when in a code,it used accept(),but it did'nt talk about it.would you explain to me where to use accept().(the chapter was about socket programming)
View Replies
View Related
Feb 18, 2014
I'm trying to send a text file over a socket, from client to server, but I doesn't work. I will demonstrate a part of the code that isn't working.
The critical part of the server look like this:
while(true) {
try {
Socket socket = fileSocket.accept();
out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String s = in.readLine();
And the client like this:
Socket = new Socket(address, number);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(Socket.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(Socket.getInputStream()));
BufferedReader fileIn = new BufferedReader(new FileReader(filename));
String s = fileIn.readLine();
out.write(s);
Now I want the s in the server to hold the same string as s in the client, but the server can't read the stream - nothing happens. I know that readLine() reads until a new line character, but it doesn't word to write and read a single character either.
View Replies
View Related
Dec 7, 2014
I have an android device which i want to be able to switch off remotely from a console hosted on the amazon cloud.The console is a simple html button that on click sends a command to a listening server on an android device that i know its ip address.
My question,is this even possible given the huge security bleach this would present to rogue apps to be able to order actions on remote devices not started by the device owner?.
The way i know the ip is via once internet is connected on an android deice,i shall then make it announce its ip that it has been assigned by the service provider,then starting a server to accept external connections.
My theory could be wrong if what i want is not permitted.
View Replies
View Related
Sep 21, 2014
I want to download objects (css , jpeg, html ,png ) using sockets in java without using httpurlconnection . How can i do this simple socket library ?
View Replies
View Related
Feb 26, 2014
I'm writing a really simple 1 on 1 chatting program thing using java.net.Socket and reading each other's messages b using writeUTF() and readUTF() of java.io.DataOutputStream and java.io.DataInputStream. Thing is, I wanna write a thread for both sides to continuously read from their respective socket's input streams while ignoring the lack of data coming through like when one user is not sending a message or something. I've written a dumbed down version of this that only reads one message from only one side and another one that sends a file, both of which work fine, I guess.
I'm using java.util.Scanner for user input, if that's acceptable, for I am not too familiar with Java's other readers. Also, I just started teaching myself about java.net.Socket, so I may not be too familiar other than the basics like how to set up a connection and how to send data using the getOutputStream() member function and stuff like that.
View Replies
View Related
Mar 3, 2014
I wrote a program to transfer a file using tcp connection, where I closed socket since the receiver need to detect the end-of--file. But now I like to extend it to multiple file for which i should not close the socket until all the files are send. I can't find a way for this. So how to resolve it.
View Replies
View Related
Apr 7, 2014
I have written a java code to transfer files from one server to another using the concept of socket programming. I got the codes from another java forum that meet my requirements. The program is said to transfer large sized files (like .mkv , .mprg movies) from one machine to another and can be used to transfer files of all formats. But after running the codes I found that the program is not able to transfer large sized files such as movies and even pdf of sizes 80mb or 111mb. When i transfer small sized files, it gets transferred and the output shows that. You can run the codes and observe it. But when i try to transfer large sized files, the program goes on running for hours. The large sized files are not getting transferred. The program has used bytebuffer but still this error occurs. The codes are as follows (I got them from this site [URL] ....)
**ClientMain.java**
import java.io.IOException;
import java.net.Socket;
public class ClientMain
{
private DirectoryTxr transmitter = null;
Socket clientSocket = null;
[Code] .....
1. ClientMain.java and DirectoryTxr.java are the two classes under client application.
2. ServerMain.java and DirectoryRcr.java are the two classes under Server application.
3. run the ClientMain.java and ServerMain.java simultaneously
Also specify the source directory, destination directory and host address of the machine in which server is running in the ClientMain.java (as per your computer). Here we are not specifying source file, instead a source directory or folder is specifying. So the entire files of source directory will be transferred.
View Replies
View Related
Jan 13, 2014
I am new to java. I want to create a socket that can serve all the network protocols. Can we make such type of socket in java.
View Replies
View Related
Apr 8, 2014
I have written a java code to transfer files from one server to another using the concept of socket programming. I got the codes from another java forum that meet my requirements. The program is said to transfer large sized files (like .mkv , .mprg movies) from one machine to another and can be used to transfer files of all formats. But after running the codes I found that the program is not able to transfer large sized files such as movies and even pdf of sizes 80mb or 111mb. When i transfer small sized files, it gets transferred and the output shows that. You can run the codes and observe it. But when i try to transfer large sized files, the program goes on running for hours. The large sized files are not getting transferred. The program has used bytebuffer but still this error occurs. The codes are as follows (I got them from this site [URL] ....)
**ClientMain.java**
import java.io.IOException;
import java.net.Socket;
public class ClientMain
{
private DirectoryTxr transmitter = null;
Socket clientSocket = null;
[Code] ....
Note that:-
1. ClientMain.java and DirectoryTxr.java are the two classes under client application.
2. ServerMain.java and DirectoryRcr.java are the two classes under Server application.
3. run the ClientMain.java and ServerMain.java simultaneously
Also specify the source directory, destination directory and host address of the machine in which server is running in the ClientMain.java(as per your computer). Here we are not specifying source file ,instead a source directory or folder is specifying.So the entire files of source directory will be transferred.
View Replies
View Related
Jun 24, 2014
We have a servlet application running under jboss 7.1.1/java 1.7 that sends http requests to another server. Everything works fine for most of the time, but occasionally (from one to a couple of times a day) we get a “Socket closed” exception. I’ve been trying to find out what might be causing this but so far I’ve been unsuccessful. By the way, this has been happening while the application was running under older versions of Jboss/Java so the version might not be that relevant.
Here’s an excerpt from the method where this happens:
. . . . .
try
{
HttpURLConnection conn = (HttpURLConnection) urlEndpoint.openConnection();
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
[Code] ....
And here’s what the exception looks like:
. . . . . .
java.net.SocketException: socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
[Code] ....
In my investigation I came across some posts that were mentioning the sockets pool the http connection is keeping, but I’m not sure whether and how this solve the problem I have.
View Replies
View Related
Sep 16, 2014
Any example of client/server socket based application using Spring and Maven where application do the following
Client sends a request with a path to any file on the server
„h Server reads the file and responds back with the content
„h Client outputs the content to the console
I am trying to follow this [URL] ....
I am using java 6
View Replies
View Related
Nov 3, 2014
I'm having a lot of problems reading data from a socket. I'm trying to read the responses of a python server. I've a
BufferedReader inputStream = new BufferedReader( new InputStreamReader(socket.getInputStream()));
And then:
char[] messageChunk=new char[32768]; //32768
List<Byte> messageBytesList = new ArrayList<Byte>();
while (inputStream.ready()) {
inputStream.read(messageChunk, 0, 32768);
for(int k=0;k<32768;k++){
messageBytesList.add((byte)messageChunk[k]);
}
}
inside a thread. Then I convert the list of bytes to a byte array using:
Byte[] messageBytes = messageBytesList.toArray(new Byte[messageBytesList.size()]);
byte[] message = ArrayUtils.toPrimitive(messageBytes);
The problem is that I often receive ArrayOutOfBound errors when I try to parse the byte array. I think that I'm reading from the socket in a wrong way..
View Replies
View Related