Reading each incoming string?
How do I read each incoming string?
import java.net.*;
import java.io.*;
public class Mystic_Client{
public static void main(String [] args){
Local l = new Local();
l.Run_Server();
l.Output();
InputThread it = new InputThread();
it.start();
class Local{
static boolean Alive = true;
static Socket server;
static BufferedReader input;
static PrintWriter socket_out;
public void Run_Server(){
try{
server = new Socket("127.0.0.1",27700);
System.out.println("Connection Opened");
}catch(Exception e){
System.out.println(e);
System.exit(0);
public void Shutdown_Server(){
try{
Alive = false;
InputThread it = new InputThread();
input.close();
socket_out.close();
it.socket_in.close();
server.close();
System.exit(0);
}catch(Exception e){
System.exit(0);
public void Output(){
String handle;
String input_message;
try{
input = new BufferedReader(new InputStreamReader(System.in));
socket_out = new PrintWriter(server.getOutputStream(),true);
System.out.print("Handle - ");
handle = input.readLine();
for(;(input_message = input.readLine()) != null;){
if(input_message.equals("~disconnect")){
Shutdown_Server();
socket_out.println(handle + " <> " + input_message);
}catch(Exception e){
System.out.println(e);
Shutdown_Server();
class InputThread extends Thread{
Local l = new Local();
static BufferedReader socket_in;
String socket_in_message;
public void run(){
try{
Socket server = l.server;
socket_in = new BufferedReader(new InputStreamReader(server.getInputStream()));
for(;l.Alive == true;){
}catch(Exception e){
System.out.println(e);
l.Shutdown_Server();
}In the public void run() it suppost to check for new incoming strings to display for my chat program. I started to try something with a for loop, but I'm just not sure yet.
Please Help!
Thanks!
Shouldn't this work? It compiles, but it won't actually display incoming messages:
import java.net.*;
import java.io.*;
public class Mystic_Client{
public static void main(String [] args){
Local l = new Local();
l.Run_Server();
l.Output();
InputThread it = new InputThread();
it.start();
class Local{
static boolean Alive = true;
static Socket server;
static BufferedReader input;
static PrintWriter socket_out;
public void Run_Server(){
try{
server = new Socket("127.0.0.1",27700);
System.out.println("Connection Opened");
}catch(Exception e){
System.out.println(e);
System.exit(0);
public void Shutdown_Server(){
try{
Alive = false;
InputThread it = new InputThread();
input.close();
socket_out.close();
it.socket_in.close();
server.close();
System.exit(0);
}catch(Exception e){
System.exit(0);
public void Output(){
String handle;
String input_message;
try{
input = new BufferedReader(new InputStreamReader(System.in));
socket_out = new PrintWriter(server.getOutputStream(),true);
System.out.print("Handle - ");
handle = input.readLine();
for(;(input_message = input.readLine()) != null;){
if(input_message.equals("~disconnect")){
socket_out.println("~disconnect");
Shutdown_Server();
socket_out.println(handle + " <> " + input_message);
}catch(Exception e){
System.out.println(e);
Shutdown_Server();
class InputThread extends Thread{
Local l = new Local();
static BufferedReader socket_in;
static String socket_in_message;
public void run(){
try{
Socket server = l.server;
socket_in = new BufferedReader(new InputStreamReader(server.getInputStream()));
for(;l.Alive == true;){
socket_in_message = socket_in.readLine();
System.out.println(socket_in_message);
}catch(Exception e){
System.out.println(e);
l.Shutdown_Server();
}
Similar Messages
-
I/o streams reading each character for analizise????
i was wondering if anyone can explain or give me sample code for the following...
id like to get user input for four numbers, each number has its own JTextfield....( i have managed this) but id like to test to see if the numbers are already in a text file and if so to relay a msg back saying security code in use....(or of sort) but if the code isnt there id like it to add it to the text file.......so is this possible, for instance if the "data.txt" file was somethng like this
12,99,05,23
22,44,11,01
and the user enters say 12,99,05,23
how would i be able to check the first digit 12 with the file then 99 and so on until its the end of file...
my basic or practise application is done using the swing api so i cant use system.out.println for the return response, however i have made a very good error class which works fine on reading files....im just stuck with verifying the numbers then i read something about using a delimiter file or comma delimiter and then completely lost the plot...
somehow this comma delimiter thingo has to fit into it to read each digit...from comma to comma but how does it all go together...
any help or guidence will be appreicated....
regard alexRead a line from the file with a BufferedReader. Use String.split() to break up the line into the individual number strings. (At the next person suggesting to use StringTokenizer instead: read the part of the ST's API to see that its use is discouraged.)
Use Integer.parseInt() to read each number string and to convert it to an int. Then you can compare it to your values. -
Reading Each String From a text File
Hello everyone...,
I've a doubt in File...cos am not aware of File.....Could anyone
plz tell me how do i read each String from a text file and store those Strings in each File...For example if a file contains "Java Tchnology forums, File handling in Java"...
The output should be like this... Each file should contains each String....i.e..., Java-File1,Technology-File2...and so on....Plz anyone help meThe Java� Tutorials > Essential Classes: Basic I/O
-
How to read each and every word from a string.
Hi all,
I have a string which is having many label numbers. if the string is lv_str, its value is like, 11111111111111##22222222222222##3333333333333.
I need to move the values alone into internal table. each value should be updated as a single row into one internal table. How to read each and every word of the string and move to an internal table.
the internal table should be like this.
11111111111111
22222222222222
3333333333333
Can any one give me a suggestion in this regard.
POINTS PROMISED.
Regards,
BuvanaHi,
If you know the format and length of the data
Use split at '#' so that you will get the individual values.
Thean append it to internal table.
Reward iof helpful. -
I have a labview sub-VI reading the string being outputted by a pH meter. The meter outputs a 5 line string and labview is only reading up to each lines carriage return, there-by giving me 5 separate strings is there anyway to rectify this and have the 5 line read as one string?
NAS1
St Petersburg FL
Labview 2010Yes, LabVIEW will automatically update. What happens is that the old serial functions still exist in 7.1 and above but the code (the block diagram) has been modified to use VISA functions. Older versions of LabVIEW are fully supported in this manner. The only way you can avoid the automatic update is to have the old serial functions in an llb and your top level VI refer to these. Having any VI that was part of vi.lib in an llb is a very bad idea and the way to fix things is to remove any VIs in the llb that are part of the LabVIEW distribution.
I don't remember how the old serial config worked and what the new version does with the VISA Configure Serial Port. Your program should only have a single serial config and you might just be able to directly replace that with the VISA configure Serial Port. -
Since approx 7am GMT I've been getting "Error in sieve filter" message with each incoming mail, worse though, since about 12 noon I cannot recieve or send mail to or from my iCloud account apart from I've been getting emails from Apple (ie I've just received a welcome one from Apple Support Communities...)!! I've had this account for years, never had a problem - it can't be the OSX Mail server because the problem is the same when I log directly into iCloud. I've tried sending emails from my Hotmail account to my iCloud account (a .mac) and just get undeliverable messages back. I'm really in the s**t now at work. : ( I just set up a Smart TV yesterday with a wireless dongle - that's the only thing I've done out of the ordinary. I've spoken to Sky who are my ISP and they say all's fine with them (although the router kept kicking my off the internet this morning which was strange...). Router seems fine now though. I'm really hoping someone here can help!!
Many thanks!!Do you think once Apple sort this out I'll get my missing emails back?
-
Reading each row of a .csv file in 12.1
I have a .csv file with the first row as header information and multiple data rows. I aim to insert the data rows into SQL database. The functionality works fine with MII 11.5, where I loaded the content using a text loader and used a flat file parser to retrieve each row. But 12.1 the flat file parser gives me a single row with all the header and value data separated by commas. How can I read each row of the *.csv to make my database insert possible? Please help!
@ Sam,
This should help me. thanks!
@ Christian Libich,
Checking the number of columns in the first row is also a part of the requirement. I may have to reject files that have incorrect number of columns. this restricts me from checking the string list output / expected column count. If I expect 10 columns in the first row and the string list gives me a total of 100 columns, I will not be able to decide if it is a csv with 10 columns and 10 rows (good file) or 20 columns with 5 rows (bad file)
@ Ajay,
Got to check this.
Thanks! -
Reading each keystroke from a console app?
I'm using Sun JDK 1.3.0_02 on RedHat Linux 7.1.
I've written a console application (no GUI, no Swing), from which I need to read each keystroke from the keyboard as it is typed.
My loop basically waits (blocks) on System.in.read(), and disposes of each byte as it is read.
Unfortunately, the way the app executes, my Java app doesn't seem to be given any keyboard input until the user presses ENTER. In addition, each keystroke is echoed to the console display, which I don't want.
Can anyone point me in the right direction to solve this? I can't use any GUI components as this needs to be a console app.
Thank you,
BryanThis can be fixed with a tiny JNI program. As long as the 'c' call getch() works the same on all platforms:
// The Java class
import java.io.*;
public class ConsoleInputStream extends InputStream
public native int read();
static
System.loadLibrary("ConsoleInputStream");
// The JNI header
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class ConsoleInputStream */
#ifndef _Included_ConsoleInputStream
#define _Included_ConsoleInputStream
#ifdef __cplusplus
extern "C" {
#endif
#undef ConsoleInputStream_SKIP_BUFFER_SIZE
#define ConsoleInputStream_SKIP_BUFFER_SIZE 2048L
/* Inaccessible static: skipBuffer */
* Class: ConsoleInputStream
* Method: read
* Signature: ()I
JNIEXPORT jint JNICALL Java_ConsoleInputStream_read
(JNIEnv *, jobject);
#ifdef __cplusplus
#endif
#endif
// The JNI 'C' code
#include "..\classes\generated source\consoleInputStream.h"
#include "conio.h"
JNIEXPORT jint JNICALL Java_ConsoleInputStream_read(JNIEnv * env, jobject obj)
return getch();
// The test program
public class Console
public static void main(String[] args)
try
System.setIn(new ConsoleInputStream());
while(true)
int ch=System.in.read();
if(ch=='\r')
break;
else
System.out.print((char)ch);
catch(Exception ex)
ex.printStackTrace();
// the build script (Windows)
cl -I\j2sdk1.4.0\include -I\j2sdk1.4.0\include\win32 ConsoleInputStream.cpp /MD /LD user32.lib /link/out:..\classes\ConsoleInputStream.dllHope this helps :) -
Need to read each sheet of an excel file and pass it to XI
Hi
Actually i need to read each sheet of an excel file and pass it to XI and will create one xml file .I am able to read the excel file by writting a custom module and it is generating the xml output from XI.But my requierment is to read the excel file and create the xml with the sheet name of the excel.suppose sheet name is sheet1, the xml file name will be sheet1.xml.if sheet name is sheet2 the xml file name will be sheet2 and so on....how can i pass this parameter from NWDS to SAP XI s i am passing the string which contains the sheet data.If I understood correct you are already reading the XLS and creating the XML (not sure if this is a separate executing body out side of XI). Are you using any sort of Object Modal in Java to read the XML? I am aware of Visual Basic object modal for Excel but not sure if one is available in Java from Microsoft.
The Object modal that you are using must be providing an iterator to loop through each of the sheet in the Excel workbook and you should be able to create the XMLs as you desired.
I would be glad to look at you module if you are doing it once the XI file adapter has picked up the excel file.
VJ -
Read into a string instead of datastream
Hi,
Would anybody please help me this? I need to read a file (e.g. test.prn) into a String (Not a stream), how can I do that?
Thanks
HungAn easier way to read each line in is to use BufferedReader.
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line = reader.readLine();
while(line != null)
//do something
line = reader.readLine();
} -
All my apple devices ring with each incoming phone call. How can I stop this?
All of my apple devices ring with each incoming phone call. This includes an iPhone 6, an iPhone 4s, and an iPad mini (FaceTime). We have 2 different phone numbers, but they now seem interchangeable? How can I direct each phone call to its rightful phone?
This is part of Apple continuity. ON all of the devices go to settings - facetime - turn off iphone cellular calls.
also don't use the same apple id for facetime. -
Cannot find anyplace to tell a page to wrap within browser margins, so one does not have to slide it back and forth to read each line::::::::::::
Yes, there are so many pages on-line that -- when made small enough to fit within the margins so one does no have to use a scroll bar on EVERY line, moving it back and forth, back and forth -- look like a FINE-print Bible page (!! tiny !!) if you keep reducing it to fit within the margins.
ALL because we cannot find a place to tell it to WRAP to FIT. Could have sworn I've seen some feature like that somewhere at one time, but if it is here, I cannot find it.
Thank you.
ginaMaybe use a style.
Add code to userContent.css
* http://kb.mozillazine.org/userContent.css
<pre><nowiki>body, body *{ white-space:pre-wrap!important; word-wrap:break-word; }
</nowiki></pre>
You can use the ChromEdit Plus or Stylish extension to have easier access to the customization files.
* ChromEdit Plus: http://webdesigns.ms11.net/chromeditp.html
* http://kb.mozillazine.org/Editing_configuration -
Read each record in an Access Database using PowerShell
I have a fix database that I need to read each record and compare it to an issue. I'm having some issues just reading each record in the specific table, when i run the below code i just get the first entry over and over again. If somone could point me in
the correct direction on how to read each record it would really help me out.
$adOpenStatic = 3
$adLockOptimistic = 3
$objConnection = New-Object -com "ADODB.Connection"
$objRecordSet = New-Object -com "ADODB.Recordset"
$objConnection.Open("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\temp\Fix.mdb")
$objRecordset.Open("Select * From Fix_Information", $objConnection, $adOpenStatic, $adLockOptimistic)
$i = 0
do {
$objRecordSet.Fields.Item("FixName").Value
$objRecordSet.MoveNext | Out-Null
$i++
while ($i -le $objRecordSet.RecordCount)
$objRecordSet.Close()
$objConnection.Close()I haven't tested this, but it looks like you're just missing the parentheses after the MoveNext method name:
$objRecordSet.MoveNext() | Out-Null -
How to read date as string (format dd-mm-yyyy) and store it as Date object
Hi. I would like to read from keyboard String with a date and put this value to Date object. How can i do this???
ThanksCheck out java.text.SimpleDateFormat.
Basically
String dateString = readUserInput(); // get the string
SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy");
Date myDate = myFormat.parse(dateString); -
Howto read url query string? Help :(
Hi everyone, I am trying to read the query string from within an applet loaded from a URL. I am loading netscape with the following URL
"http://localhost/mypage.html?param1=help"
I am using code:
System.out.println(getDocumentBase().getQuery());
and all I am getting is a null?
This works with appletviewer so could someone tell me what is going on. I have searched the forum but it seems no answer yet exists for this. Perhaps its not possible?
Info:
OS: Redhat Linux 8
java version "1.3.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)hi,
can it be that there is a problem with netscape?
it would suggest to try on ie, but you use linux and i dont think theres an ie-version for linux available ;P
i would try it on a different browser like opera or something.
thats my suggestion.
hope this helped
cu Errraddicator
Maybe you are looking for
-
I have problems with firewall and sync my iPhone with iTunes through wi-fi connection.
My iTunes can't find the iPhone when the firewall is turn on. I tried to permit the apples applications in the firewall but nothing happens. My computer and iPhone are on the same wi-fi network. When I turn off my firewall, I can see my iPhone in iTu
-
Can't figure out how to do a specific calculation
I have a report that is broken into columns in the detail section. From the data in that section I need to create a formula that looks something like the following: (column A - Column B)/column A Now because I have it formatted with multiple columns
-
Errors - drawing a text curve in flex with flex 3 with flex 3.5 framework
Is that necessary in drawing a text curve in flex we need flex 4 with flash player 10, actually i have flex 3 with flex 3.5 framework but it is showing error like this : This is my code: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx
-
Custom Cursor and Drag Image in 1.4 DnD
What is the proper way to provide a custom cursor and drag image in 1.4 DnD? Say we initiate the drag on a component that supports data transfer (such as a JTree).
-
Web Dynpro Model Generation for Application Services
Hi Experts, I'm currently experimenting with the new functionality provided by CE, but there is one thing that I can't seem to figure out. How does the new Web Dynpro model generation work with regards to CAF Application Services? I'm trying to call