•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 402,906 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,123 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 838 | Replies: 5
![]() |
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
I need some help. I have to translate a c app into java. Which would be no problem if I knew c. Is there a good uber begginers level tutorial somewhere, that i might be able to figure out what this c code is doing? I mean, i am seeing things like "struct" which I have no idea what that is and pointers which java doesnt use. Anyone have an idea of where i should look.
•
•
Join Date: Jun 2007
Posts: 26
Reputation:
Rep Power: 2
Solved Threads: 1
•
•
•
•
I need some help. I have to translate a c app into java. Which would be no problem if I knew c. Is there a good uber begginers level tutorial somewhere, that i might be able to figure out what this c code is doing? I mean, i am seeing things like "struct" which I have no idea what that is and pointers which java doesnt use. Anyone have an idea of where i should look.
I think you'll have a big problem there. Most probably you will be able to make the same program done in C, but in Java. The problem is that it won't be like "translating" english to spanish. Firs of all, C is an imperative language, while Java is an object oriented one. Like you've said, you dont have pointers in java, and thats only one of the "heavy" differences if you've never used them. For instance, in C you don't have objects ( you can try to simulate this concept using ADT's, but thats another subject ), you dont have classes, inheritance or polymorfism and another bunch of difs. So, as you can see, its a very different languaje, from several points of view. I don't know how complex its the code you have to "translate" but you could start by researching a bit about C using your best friend Google. Then you can ask whatever you don't understand about it and if you still cant figure what the purpose of that code is, you can send it to me and I'll try to do my best to help you. Good Luck!
PS: I skipped the explanation about structs because you need to know some previous stuff before getting there. Look for tutorials!! You'll find a lot!
"And often enough, our faith beforehand in a certain result is the only thing that makes the result come true." ( William James )
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Hey, Thanks for the info. I would take you up on sending you the c code, but it is a homework assignment, and I dont want you to think I am fishing for someone to do it for me. Having said that, if I did send it to you, all I really need is an explanation of what the code is doing. Once I know what the c code is doing, then i can easilly (hopefully) re-write another server / client app in java. I will post the c code if you request, but I really dont want you to think i am looking for an easy out. I want to do it, but I just dont know c code from a hole in the ground. Actually i will attach a text file that has two c classes(if they are called classes), but i put them into one text file.
•
•
Join Date: Jun 2007
Posts: 26
Reputation:
Rep Power: 2
Solved Threads: 1
•
•
•
•
Hey, Thanks for the info. I would take you up on sending you the c code, but it is a homework assignment, and I dont want you to think I am fishing for someone to do it for me. Having said that, if I did send it to you, all I really need is an explanation of what the code is doing. Once I know what the c code is doing, then i can easilly (hopefully) re-write another server / client app in java. I will post the c code if you request, but I really dont want you to think i am looking for an easy out. I want to do it, but I just dont know c code from a hole in the ground. Actually i will attach a text file that has two c classes(if they are called classes), but i put them into one text file.
Your welcome! Please, don't think I was trying to make you take the easy way. As I told you in my previous post, you should try finding a basic tutorial in order to get some information about how is data representation in C, reading about stuff like: built-in types, arrays, pointers, structs & unions, types definition using typedef, etc. After that I recommend you looking for some information ( know i've seen the code, I can lead you a bit more ) about socket programming in C. I dont pretend you to know how to program this stuff by yourself but if you get an idea of what is the operational insight of some functions like
socket I think you will get the main idea of the code. If you have tried with that and you still want my help, I can tell you the "idea" of both client & server. Good Luck!PS: What you've put in that file are not classes, they are functions. In particular they are the main functions of each program ( client & server ). Each program coded in C, MUST have a main function because thats the entry point of the program( like in java, but in C is just one more function ).
"And often enough, our faith beforehand in a certain result is the only thing that makes the result come true." ( William James )
•
•
Join Date: Aug 2007
Posts: 74
Reputation:
Rep Power: 2
Solved Threads: 9
Java provides its own set of libraries for Socket Programming. Refer java.net package. The code provided by you uses C specific libraries for socket programming.
However, the program has two parts Client and Server. The client reads two arguments from command line. They are the program/file name and the host with which you want to connect to. In case of Java, you only require one argument i.e., the host-name.
It then opens a Socket to communicate to the Server.
The program can then uses an infinite loop to get and send messages from and two Server.
The Server part also does some sort of similar stuff. It does not require any host name as it is itself the host.
The Server binds itself to a socket so that it can listen to requests and process them.
The same can be achieved very easily in Java. What you here need to understand is the concept that Java and C uses for Socket programming. You cannot straight away convert a C program to Java because of the differences in them, their architecture and the libraries used by them.
However, the program has two parts Client and Server. The client reads two arguments from command line. They are the program/file name and the host with which you want to connect to. In case of Java, you only require one argument i.e., the host-name.
It then opens a Socket to communicate to the Server.
The program can then uses an infinite loop to get and send messages from and two Server.
The Server part also does some sort of similar stuff. It does not require any host name as it is itself the host.
The Server binds itself to a socket so that it can listen to requests and process them.
The same can be achieved very easily in Java. What you here need to understand is the concept that Java and C uses for Socket programming. You cannot straight away convert a C program to Java because of the differences in them, their architecture and the libraries used by them.
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
thank you all for the explanations. Currently i have written two small java classes using java.net libraries. I am unsure if i need to create threads to start everything off or not but the client handles reading the input from the command line, puts it into a datagram packet, and sends it off to the server. The server recieves it, gets the data, ip, etc.. In the c code what does it do with the data it recieves? Does it just echo it back to the client? That is what i am assuming from the comments. Again, thank you all for explaining this very simple c stuff to me. I feel kinda retarded having to ask for someone to explain such a thing to me. I will finish the java stuff this weekend and i will post what I have so you guys can critique me.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Java Game Characteristics (Java)
- Java Game Characteristics (Java)
- Java open internet browser (Java)
- Sentinel control (Java)
- Browser's Language Interpreters (Computer Science and Software Design)
- Java DSW algorithm Coding (Java)
- calculate the grades for a student using if..else statements. (Java)
Other Threads in the Java Forum
- Previous Thread: java.lang.NoSuchMethodError
- Next Thread: granting write access to sun appserver


Linear Mode