Where To Use Accept Routine In Socket Programming
Sep 2, 2014i 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 Repliesi 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 RepliesI 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.
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 RelatedI 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.
I want to write classes with methods that perform JDBC operations that throw SQL exceptions. For many of the methods, I'd ideally like to be able to have them catch exceptions and just send them to a standard Logging system "IF" the code that calls the methods is not going to catch the same exception. However, I'd like the "option" to have code that calls these methods catch the same errors if I want to but not "Require" the calling routines to catch them.... so I don't want to declare the methods with a "throws" that would require all calling code to Try/catch.
For some background, the logic behind what I'm looking to do is that there will be lots of places where these classes and their methods may be used where the code is basically "throw away" scripting code where just having error logs generated is more than sufficient. However there are also places I want to use the same classes/methods that I would want to handle the exception differently. So, for at least half the places I want to use these methods, there's no good reason to require cluttering the calling code with Try/catch, but when I DO want to handle the exceptions, I'd like them to get passed up to the calling routine so I can handle them in a way that is appropriate for the calling routine. Does that make sense?
I guess I'm kind of looking for is the ability to "override" the catch of a called method "IF" I want to but to treat the method as though it doesn't throw any exception "IF" I don't want to override the called routines catch logic.
Is this possible?
I'm just trying to learn how to cut the IDE out of my programming.I've added C:Program FilesJavajdk1.7.0_55in to the environment variables (path), am navigating to the src folder where my java class exists in cmd prompt, and then typing "javac CaesarCipher.java", but its complaining that it can't find the file.
Is the problem something to do with the relative address of the compiler to the file it needs to run? Just a stab in the dark on my part. Or do I have to add the JRE path as well as the compiler?
I find myself asking these two questions because I see them as relating. First question is; I always write
Java Code: f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mh_sh_highlight_all('java');
(where f is a JFrame object)
to set the close for the JFrame. What I don't get about this is what is going on in the parenthesis. I looked in the Java Documentation, and it says an int goes inside. In that case, I don't really get what the word JFrame is doing there. Overall, please explain what is inside the parenthesis of that line and why it has to be there.The second question is a generic question. I notice a lot of times an object will be created, and as its parameter, you will have to instantiate an object. an example would be
Java Code: Class f = new Class(new Object) mh_sh_highlight_all('java');
What does it mean when an object gets created inside of a new object? Why is putting Java Code: new Object mh_sh_highlight_all('java');
ever necessary when concerning the two parenthesis?
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.
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 ?
The goal is as follows: Write a UDP 'CompressionServer' that will take input from the user until it sees a "magic string" at which time it will create a compressed and uncompressed version of the file in the file system.
So, I need to integrate the following "Zip" code in to my UDP server code (which already creates the uncompressed file)... That is where I am stuck at now. My first few attempts had the Zip code after I write to "fout" but that failed to create a ZIP file.
I guess the main point here is what are the key pieces of the ZIP code that I should include and what would be the best spot to place them in my server code...
Zip Code:
import java.io.*;
import java.util.zip.*;
public class Zip {
static final int BUFFER = 2048;
public static void main (String argv[]) {
try {
String fileInput = argv[0];
String fileOutput = argv[1];
[Code] ....
class triangle
{
public static void main (String[] args)
{
System.out.println("Provide three side lengths - 000 to terminate.");
int a = In.getInt();
int b = In.getInt();
int c = In.getInt();
[code]....
My problem is that when I enter 5,2,5 it should be isosceles and acute but it comes out as isosceles and obtuse, and when I type 5,5,5 it comes out equilateral and right. The only one that works is if I enter 3,5,4 it will come out as scalene and right. I been at this for a while and my math looks correct.
I'm having problems programming the LightsOut game. I made a 5*5 matrix and filled it in with 1's and 0's, where 1 means on and 0 is off, they should be placed randomly. The player can choose a field, for example "A2", and the matrix should change according to the input. My problems are how can I choose a field ? How can I display the new matrix after playing the first step and so on?
PS: I'm using the console because I'm still not good with JOptionPane commands.This is my code for the Game:
public class TestLightsOut {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] blocks = new int[5][5];
String[] letters = { "A", "B", "C", "D", "E" };
String[] numbers = { " ", " ", " ", " ", "1 ", "2 ", "3 ", "4 ", "5 " };
String[] line = { " ", " ", "_", "_", "_", "_", "_", "_", "_",
"_", "_", "_", "_" };
[code]...
What is difference between algorithm and programming?How to develope algorithm knowledge?
View Replies View RelatedI'm learning Java and came across saving user preferences. As I was learning I also learned about object serialization and File input/output. I've heard that the windows registry can be a problem because it can quickly become a dumping ground for uninstalled programs. So my question is why should I use the Preferences API? and is it really good practice to program to the registry for saving information? I'd also like to be in good standing towards the programs I write so if it is common practice to write to the Registry how exactly would I manage the information that I dump into the Registry?
View Replies View RelatedWe are working with Java and Eclipse..One of the assignments asks to "Write an application that determines the number of coins in a jar and prints out the total in dollars and cents. Read integer values that represents the number of quarters, dimes, nickels and pennies. Use a currency formatter to print the output."
View Replies View RelatedI would like to bring a project in java program written by me, that interfaces with a fingerprint reader (already purchased, the reader U.are.U 4000b) and as I'm using fingerprint sdk sdk's Griaule.
View Replies View RelatedI am looking to program a simple genetic algorithm in Java but where to start.
" In a computer language of your choice, implement a simple genetic algorithm (GA). That is, write code for a generational GA which uses a binary encoding, tournament selection, single-point crossover and bit-wise mutation" ....
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?
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).
I have a GUI with a JTextField. I need to check that the input entered by the user is made up of only integers.
For example I accept: 1, 10, 530, ...
I do not accept: -10, 1.5, -6 ...
I would like to implement this control by using a regular expression so I would have a code like that.
JTextField text = new JTextField();
String input = text.getText();
boolean bool = checkInteger(input);
if(bool)
System.out.println("Ok");
else
System.out.println("Error");
The checkInteger(String input) method should check if the input string is correct or not.
How can I do to implement this control with regular expressions?
Is there an easier way to do it?
what is meaning of Open Source in programming lenguages?
I want to ask this question reagrding this context that if some company or some products that says "This is open source" all codes are available Then it it mean..
1)We can reuse,re produce,distribute this code,modify and sell it for commercial purpose?
I know there is license also attach with a OpenSource.
But What exactly meaning of OpenSource?
A friend and I are working on a project in which we must test "super anagrams" (anagrams in which all characters in the first string are found in the second). We have a driver and definitions class pasted below:
Definition
class SuperAnagram{
String left = new String("");
String right = new String("");
[code]....
In the driver class, we get "cannot find symbol" errors at the beginning of cleanStrings and isSuper, both inside and outside of the if statement.
Which of these is not a real differentiator for programming languages:
a) Object-oriented / Process-Oriented
b) Interactive / Automated
c) Interpreted / Compiled
d) Strongly-Typed / Weakly-Typed
e) All of the above
f) B and C
g) B and D
Almost all support OOP, Interactive/Automated, Interpreted/Compiled but not sure about Strongly typed/Weakly typed.
I am trying to create a fortune teller and everything is running fine except the program does not prompt you to answer the questions
Do you like donuts?
and
What did you have for breakfast?
Here is the code this is in Bluej :
import java.util.Scanner;
public class FortuneTeller {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to Fortune Teller");
[Code] .....
Use Java to write and run a simple console-window program for checking passwords. The program must satisfy the following requirements:
-When the program runs, it should first print its name, e.g., Password Checker
-The program should next prompt the user to enter a username, e.g.,
Please enter your username:
-The program should next prompt the user to enter a password, e.g., Please enter your password:
- If the user enters a correct password, i.e., one that matches an internal secret password, the program responds. You are approved by access control!, and quits.
-If the user enters an incorrect password, the program responds
Try again:
-If the user enters a correct password matching the secret one, the program responds. You are approved by access control!, and quits.
-If the user enters an incorrect password, the program responds
package class1;
import java.util.Scanner;
public class class1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
[code]....
Basically, I'm just trying to let the user enter the name. It crashes whenever the input isn't an int. Also, here's the bit of code I'm using that has to do with that. I don't feel like putting the entire class, so here's that bit of code:
PHP Code: String yourName = user.nextLine(); mh_sh_highlight_all('php');
Anyway, I just haven't figured out how. Also, the scanner is called user in this class.