Rusty Shackleford

Ranch Hand
+ Follow
since Jan 03, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rusty Shackleford

HTTP also makes use of TCP and IP layers of course, but that Socket which lives in TCP and IP layers doesn't know HTTP. Write a socket program to connect to googles http server, you can connect, but would have to do a lot of additional work(implement relevant HTTP functionality) to pull off a meaningful conversation.

The purpose of a protocol is so two or more machines can talk. If they are speaking different languages they can't communicate, not even with hand gestures.

Did you write both client and server? if so change one to match the others protocol, or can at least add on to it doing something like the adapter pattern if you want to keep the current protocol intact.
I am writing a series of scripts that run and use output from a variety of network tools. What tools and what arguments will be determined at runtime, and these arguments can get complex. For example running nmap -PA -sV -O -T4 -p80,443,8080,8443,9000-10000 <target>. If the target and arguments are know before running it, it is simple, either use `...` or %x{...}, but this method seems to not take string parameters only literals, using system makes it impossible to capture output which is what I need to do. I am using open3 which works but doesn't seem to be ideal. I would like to have to be free from constructing the complete command line string, but this is the only thing that seems to work.

If I try:
inp,out,err = popen3(@tool, @args)
inp.puts @target
inp.close
It works with one argument, but not multiple. This would be perfect because I will likely have a list of targets, but arguments may change based on other runtime criteria. The problem is that this only works with 1 argument, passing in multiple arguments as either a single string or many arguments results in failure: either a broken pipe or nmap can't see the target. So my solution is to build a single string and pass that:

inp,out,err = popen3(@tool)
inp.close

Where @tool is something like 'nmap -PA -sV -O -T4 -p80,443,8080,8443,9000-10000 <target>'. Is there a better way to accomplish this? This works but having to build a lot strings during runtime is going to slow things down considerably as I may have hundreds of targets and a dozen or more tools to run and parse data from.
9 years ago
System.out.println(a) and System.out.println(a.toString()) are equivalent. They both call toString which returns a string, which println prints. All objects in Java have a toString method because it is part of Object.

9 years ago

Vonique Leary wrote:

Look at the "doStuff" method. "B = new Cat();" Remember what that means? B has it's bit of paper wiped and a new address (reference, bit pattern, call it what you will) written on it. This points at a new Cat on the heap.

A is still pointing at the old Cat. A's bit of paper (address/reference/bit pattern) has not been changed.



Try as I might I cannot get this question answered, and I think it is the key to the entire confusion for me:

In the method doStuff, B is just the parameter is it not? A is getting passed to it. So when you say that B has it's bit of paper wiped and a new address aren't we really talking about A? Because then you say A is still pointing at the old Cat. So I will ask again, there is an A (passed as an argument to the method to act as the B parameter) pointing to a new Cat, but then you say A is still pointing to the new Cat?

Am I confused about the method scope? Is it because A in the doStuff method goes out of scope?



Scope is irrelevant to this problem.
Assume Cat overrides toString and prints the name of the cat.

Both A and B are in the same scope at all times. Passing the value of A to another method is not any different then the above example

The output would be:


The only thing that matters is the bit pattern stored in memory that represents A and B. Hopefully it is clear that the objects that reside at 0x0a and 0x10 and 0x14 are not the same object, even if the cat name is the same. Another good lesson is even if an overriden equals() or implemented compareTo() return true, that does not mean that the 2 references being compared both point to the same object.

9 years ago
Perhaps before posters recommend an existing library, they find out what the goal is. I see this all too often when people ask for help when implementing protocols or data structures. Learning how to use an existing Collection class isn't nearly as useful as learning how it really works. Anyone can make an API call.

It isn't always the case that "existing and 'well' tested libraries" are better. For example there are cases where writing your own data structures is better then using what is in Collections. But I agree that generally using existing solutions is better and said exactly that in my first post.
9 years ago
If you close the streams that closes the socket. Unless you need the socket for some other reason, all you need to do is pass the IO stream references.\

Here is simple code to show it:



output:

Simplicity is probably the most correct answer.

Regardless, if you have a program that has several billion items to store, an array of any type is the wrong data structure to be using. There is a reason disk based data structures were invented. Of course this gets into how databases are actually implemented and likely further than you need to go.
9 years ago
Do not use readline() on a stream attached to a socket. Different platforms use different bit patterns for marking the end of a line, using it in network programming can cause all sorts of behaviors, usually causes it to block indefinitely because it is expecting a specific bit pattern to know when it is done. I stopped looking at your code once I saw those readlines, you may have other issues, but this is the big pointy one.

Quite often in network programming what you are writing will interact with a variety of operating systems and servers/clients written in many different programming languages. This requires special care. I recommend going over the Network and IO trails here. Another good resource is Java Network Programming by Elliot Harold, it talks about sockets, IO, threads and other critical topics in detail.

I disagree with the idea to use JavaMail. Nothing teaches you how email works(or whatever else you are wanting to learn) if you do it yourself. It makes you a self-reliant programmer. Of course, I wouldn't advise rolling you own for production use unless you really know what you are doing. Same goes for any protocol, data structure, etc.
9 years ago
I think it is a non-issue.

It is not that difficult to replicate the contract of any method. Your code is copyrighted, so that will stop most people from copying and pasting your code. The bad guys are almost always terrific programmers so can easily reverse engineer your code no matter what you do or just figure out what a method is doing and just write their own version.

How many millions of dollars does a company like Microsoft spend to try and stop this? Their code is always cracked and broken in short order. All without source code.
9 years ago
I think you shouldn't lump PHP into the same pile as Ruby, Perl or Python. Its value outside its main use is very limited. Ruby can be used anywhere and for just about anything. The term scripting language doesn't really apply to it. It is the same with Perl and Python as well. It is as much of a scripting language as C, or Java is.

The only thing I remember from Perl is that it is truly a write only language.

Python is a lot more challenging to get into and is fairly inflexible, that is, adding something not intended is always an ugly hack. It rigidity makes it tougher to get into, and I have been writing Python code off and on for 5 years and I still am not used to lining up blocks. It makes it very annoying to add in(and remove!) a debug statement. When using Python OO, it is a horrible mess with all those selfs hanging around everywhere, this is one of the few places the java language is better(The java language is a horrible mess, although not quite as bad as C++, its true power lies in its libraries and JVM). Its main advantage has nothing to do with the language, and that is the performance that bytecode compilation brings. I am not sure it makes python worth using in many cases.

Ruby is a far more elegant then either Python or Java. It is also fun to work in, writing good java code is drudgery, ruby is just plain fun. A good example is to compare several Java based API's that try to mimic ActiveRecord to AR. They are all very clumsy and it has everything to do with the rigidity of Java. Rails is so slick because of Ruby. Once we can compile ruby code in bytecode happens, it will be interesting to see how it effects performance and usage of the language.

Patterns are almost completely language neutral, as it should be. Heck you can adapt just about any pattern to C or even assembly! That said a good Ruby pattern book is Design Patterns in Ruby by Russ Olsen, its main value is not the regurgitation of what the patterns are which were already done so well in the GoF book, but it shows how to correctly use Ruby's OO system.
9 years ago
PrintWriter will not work because it doesn't have any methods to seek or read to a certain place in the file. A quick look at its methods should show that.

The suggestion to use RandomAccessFile is what you need to look up. Go to the API Docs, and see if it can both read and write, and also seek to a certain point in the file. This tutorial talks specifically about the class and this tutorial goes over another method.
9 years ago
It is more then semantics, but the confusion is a result of the unfortunate decision to call them references. What they really are is implicit pointers. Pointers that hide the pointer arithmetic away from the programmer.

Java is pass by value, always. That value can be a primitive or an address(or whatever other representation that the JVM uses) of the object. Most common languages only support pass by value, except c++ which supports both.
9 years ago
gem install <name of gem> --include-dependencies

The --include-dependencies is optional, but it is a good proactive thing to do. Make sure you are root/sudo/admin.

To install a local gem you need to untar it first. and then use gem to install the *.gem file.

What are the specific errors that you get when trying to install rails?

You best bet is to install all gems natively, then they can be used system wide with no fuss.

9 years ago
Right, but the problem is still the same as the mysql problem, the server is shutting down the socket.
Rob Prime had the beginnings of a simple solution. IIRC, you can you InetAddress to see if you can get ICMP responses, ie ping. Of course this depends on if the target address has a machine that doesn't block ICMP.
10 years ago