I am attempting to create a simple users online but cant seem to get the String vector to update properly.
Client Code: (Both vectors are global)
else if(command.equals("GET USER LIST")){
test = (Vector)ois.readObject();
for(String s: test){
if(!usersConnected.contains(s)){
usersConnected.add(s);
jlConnUsers.setText(jlConnUsers.getText() + s + " ");
}
}
System.out.println("Test array " + test);
System.out.println("User array " + usersConnected);
}
Server Code:
public void getActiveUserList(){
for(ClientConnection client: activeConnections){
String user = client.getUserName();
if(!activeUserList.contains(user)){
activeUserList.add(user);
}
System.out.println("sent TO client FULL USER LIST:" + activeUserList);
}
}
So, client connects, hits a button "Get user list" which gets sent to the server, server goes through hashmap, adds all current client names to a vector and sends it back...
My issue: If I connect one client and get the user list, it will display the SINGLE name properly. If I connect two clients and attempt to get the user list, client 1 will not receive the updated vector EVEN THOUGH the server is sending the correct vector.
The Server always sends the correct vector with the correct user names.
Client 1: Name 1 (Will not update after more clients connect)
Client 2: Name 1, Name 2 (Will not update after more clients connect)
Client 3: Name 1, Name 2, Name 3 (Will not update after more clients connect)
If I access the getusers BEFORE another client connects, I can not get the correct vector again.
Im fairly certain im missing something extremely small here, I could be wrong. Any ideas? Thanks!
I believe this has been solved. REFERENCES to the vector were being passed instead of the new vector.
Calling the "reset" method prior to sending over the object seems to have fixed this.
Related
I have currently a huge problem for which I need help for it.
Currently I´m not loading all emails at once.
I found here the following function for it:
Message[] messages = emailFolder.getMessages(start, end);
I know I can use SortTerm for sorting the emails:
SortTerm sortTerm[] = new SortTerm[] { SortTerm.REVERSE, SortTerm.DATE };
Message messages = ((IMAPFolder) emailFolder).getSortedMessages(sortTerm);
But than I will load again all emails.
How can I use together:
- search
- sort
- and use getMessages(start, end)
A sample code would be very helpful.
Many thanks
To be clear, when using IMAP no messages are "loaded" when you call getMessages. All that happens is that the JavaMail client creates a Message object that refers to the message on the server, and sets it up so that the Message object will fetch the data for the message on the server when you ask for it.
You could create a SearchTerm that uses a pair of MessageNumberTerms to constrain the message to be within a certain range just as you were doing with "start, end". But you should ask yourself whether you really want to sort all the messages in the mailbox first by message number (effectively a forward sort by received date) and then reverse sort them by sent date. What exactly are you trying to accomplish?
So I've tried to send players to the lobby server when they type "/lobby" by using this code:
Bukkit.getServer().dispatchCommand((Player) player, "server lobby");
But in game, it returns "Unknown Command. Type "/help" for help."
I've also read to try this code, but I don't know what to put in place of "a", "b", and "c"
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("a");
out.writeUTF("b");
//applies to the player you send it to. aka Kick To Server.
Player player = Bukkit.getPlayerExact("c");
player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
So my question is why does the first method not work? Also, how do you make the second solution work? Is there code I need to put in the bungee server?
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF("ServerName");
player.sendPluginMessage(PluginObject, "BungeeCord", out.toByteArray());
This is what you are looking for. To answer your question, "a" is always "Connect". "b" is the name of the server that you want to connect to (In your case this is "lobby"), and "c" will the name of the player (This is because in the example that you've supplied your getting the player by their name, however if you've already got the player object, this isn't needed).
And just so that you understand why dispatchCommand doesn't work, it's because when you do /server on your client it sends a packet to the Bungeecord as that's what your client is connected to, and it will intercept that command packet read it and see that it's a server command. It will then proceed to connect you to the right server. If you use dispatchCommand on the Bukkit server it will execute the command as though it just received an command packet, which means it never sends out any sort of message to the bungeecord or to the client to get it to execute a command. The dispatchCommand method will only be run on the bukkit server.
The reason that the second solution works is because in the Minecraft protocol there's this thing called the plugin messaging channel, for custom messages between the client and the server. And yet again as the Bungeecord sits in the middle of the client and the server, it listens on certain messages, and any of them tagged with Connect will connect a player to the specified server. I hope this makes sense.
I'm quite new to java programming and tried doing a simple program where I have a server and 2 other users that can communicate by sending simple message (string). Everything works, but I have a problem when I use the readObject method. Basically, if the second user write a message before the first user, that message will not appear on the server screen until the first user send a message. It seems that the method readObject will freeze the program until it actually receives and object from that user, and will then continue :
while (true) {
message = (String) input[0].readObject();
showMessage(message);
message = (String) input[1].readObject();
showMessage(message);
}
My question is : is there a way to let the second user send an object before the first one if he's the first one to send something? Do I have to create a separate thread for each user? Thank you!
I'm tried to get AS400 TCP Connection Status. but i'm failed :( can anyone help me to do this. i'm new to JT400 java development. please help me friends.
i want to get IP address of a job
i want to get TCP Connection Status using that (1) IP address.
Please help me
Thank you!
Edit :
i got this class
com.ibm.as400.util.commtrace.TCPHeader
It's return this informations
getACKFlag()
getAckNum()
getCheckSum()
getCWRFlag()
getDataOffset()
getDstPort() ..etc
now i want to get this informations. its mean, how to get TCP status using this class.
Please help me
Thank You
To get the IP address of a job:
System.out.println("IP address " + job.getValue(job.CLIENT_IP_ADDRESS));
The commtrace classes are not real-time. They use a trace file which was created on the IBM i server at some earlier time. In order to create that trace file, see the Javadoc for com.ibm.as400.util.commtrace.CommTrace Basically you will need to run the IBM i commands STRCMNTRC, ENDCMNTRC and DMPCMNTRC. Then use commtrace.CommTrace to create a trace file formatted so that the other commtrace classes can read it.
EDIT: Add code snippet from commtrace.Format Javadoc
import java.util.*;
import com.ibm.as400.access.*;
import com.ibm.as400.util.commtrace.*;
public class TestCommTrace {
public static void main(String[] args) {
try {
Format f = new Format("/buck/linetrace");
FormatProperties fmtprop = new FormatProperties();
f.setFilterProperties(fmtprop); // Sets the filtering properties for this Format
f.formatProlog(); // Format the prolog
Prolog pro = f.getProlog();
System.out.println(pro.toString());
if(!pro.invalidData()) { // This is not a valid trace
Frame rec;
while((rec=f.getNextRecord())!=null) { // Get the records
System.out.print("Frame " + rec.getRecNum().toString()); // Print out the Frame Number
System.out.println(" time " + rec.getTime().toString()); // Print out the time
IPPacket p = rec.getPacket(); // Get this records packet
Header h = p.getHeader(); // Get the first header
if(p.getType()==IPPacket.IP4) { // If IP4 IPPacket
if(h.getType()==Header.IP4) { // If IP4 Header
IP4Header ip4 = (IP4Header) h; // Cast to IP4 so we can access methods
System.out.println(h.getName()); // Print the name
System.out.println("IP4 src:"+ip4.getSrcAddr() + " dst:" + ip4.getDstAddr());
System.out.println(ip4.printHexHeader()); // Print the header as hex
// Print a string representation of the header.
System.out.println(ip4.toString()); // hex string
//System.out.println(ip4.toString(fmtprop)); // very detailed
while((h=h.getNextHeader())!=null) { // Get the rest of the headers
if(h.getType()==Header.TCP) { // If its a TCP header
TCPHeader tcp = (TCPHeader) h; // Cast so we can access methods
System.out.println("TCP src:" + tcp.getSrcPort() + " dst:" + tcp.getDstPort() + " checksum:" + tcp.getCheckSum());
System.out.println(tcp.toString()); // hex string
//System.out.println(tcp.toString(fmtprop)); // very detailed
} else if(h.getType()==Header.UDP) { // If its a UDP header
UDPHeader udp = (UDPHeader) h; // Cast so we can access methods
System.out.println("UDP src:" + udp.getSrcPort() + " dst:" + udp.getDstPort());
System.out.println(udp.toString());
}
}
}
}
}
f.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
EDIT: Some more detailed information
1) On the IBM system, someone with special permission must run STRCMNTRC and collect communications trace information. This trace file contains all of the TCP packets that flowed between the IBM system and the outside world. For example, if the trace runs for an hour, it will collect every packet the system sent and received during that hour. The trace data is stored in a format that is special and can not be directly read.
2) To make the trace data readable, use the DMPCMNTRC command. This will create a flat text stream file out of the trace data. This data needs to get to your PC so that the com.ibm.as400.util.commtrace classes can work on it.
3) On your PC, run com.ibm.as400.util.commtrace.CommTrace. This will create a file in a simple text form that com.ibm.as400.util.commtrace can process. I put mine in /buck/linetrace. It is important to understand that there are hundreds or thousands of packets in this log, and every one of them has the information you ask about in the question. There is not one single ACK flag, there are many hundreds of them. In order to understand what is happening, your program will need to read a packet, get the header, then the status, get the data and then read the next packet, and the next and the next, all the way through them all.
4) In order to filter by IP address, you can either use setFilterProperties() or have your code check the IP addresses in each packet header and only process the headers you want to.
It is important to understand that the 'status' you are looking for is not a property of an IP address, it is a property of a TCP packet. There is no way to ask the system for the ACK flag of an IP address because there is no such property to be returned. The only way to get these things is to record them at the instant the packet is read or written by the system.
I would be very surprised if you really need these flags; almost no one does. Usually, 'connection status' means a way to determine if the machine is running or not. ping is the typical way to answer that question, but not all machines will answer a ping. For those machines, the best way is to try to connect to the machine and port you want to test.
I am writing a networked multi player game where players use their own client and server handles all the data processing...
I have finished writing for the game with one server.
What I want to do is, I will have a main server which will send information about different game rooms and players will be able to connect to the game room they want.
What I have in mind is if player click set up new game room, the client will tell server to set up new game which will create a new server and add the information about that server to the main server.
I am keeping secondary servers as ArrayList...
String line = in.nextLine();
if (line.equalsIgnoreCase("new game")) {
servers.add(new SecondaryServers(secondaryPort)); // starting secondary server
secondaryPort++; // this is to keep track of port number
System.out.println(i + " secondary server(s) started"); // printout in main server's console
}
When I do it that way, it started a new server at the first time, but it never goes to the state to print out to the console.
Please help me out to create new servers from the main one :)
I think there is a ServerSocket.accept() method is called from within SecondaryServers. accept() is a blocking method so you should start SecondaryServers in a new Thread.