Solved

Socket Communication Java to C

Posted on 1998-08-31
6
238 Views
Last Modified: 2008-03-17
Server program written in C, which has got lot of structures.  I have to write the client program in JAVA.?  How can I do it.?  Any approach.?  Any examples.?
0
Comment
Question by:Arumugam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:Arumugam
ID: 1223073
It is very very urgent.   Expecting answer as soon as possible.  Thanks in advance for the help.  
0
 
LVL 3

Expert Comment

by:sailwind
ID: 1223074
It shouldn't really matter what language the server's written in. As long
as you know what the data in the packet that it sends you and what it
expects, it should work perfectly fine.
0
 

Accepted Solution

by:
dys earned 50 total points
ID: 1223075
Arumuqam:
   Just as sailwind say,No matter what language the server and client programs,only the method of communication server and client is same.if server uses Datastream,the client must use Datastream,is server users Datapacket,the client must use Datapacket.So you must know your server use what method and host address and  port by server using.
      The example of client program in JAVA(the method of communication is datastream):
        import java.net.*;
      import java.applet.*;
      import java.io.*;
      public class Client extends Applet
      {
            DataInputStream dis;
            BufferedInputStream bis;
            InputStream is;
            String s;
            Socket sc;
            public void init(){
            sc=new Socket("hostname or hostIP",server_port);
            is=sc.getInputStream();
            bis=new BufferedInputStream(is);
            dis=new DataInputStream(bis);
            }

            public void start(){
            while(true){
                  //read line from socket port:sc
            s=dis.readLine();
            ...
            ...
            }
      }

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Arumugam
ID: 1223076
I agree to you.. can you clear this point.
Server is expecting a structure in the form of "integer, unsigned short, string" at one time.  How to send this data to the server.?  So that server will take that and respond for me.  Hope you know that, unsigned short is 16-bit in C and 32-Bit in JAVA.  

0
 

Author Comment

by:Arumugam
ID: 1223077
Can you clear this point..  I agree to your answer.
Assume that server expecting a buffer which contains "integer, unsigned short, string".  How the client has to send that buffer in order to take care of unsigned short value.  (because unsigned short value is 16-Bit in C and 32-Bit in Java).
0
 
LVL 8

Expert Comment

by:diakov
ID: 1223078
Another concern is the byte ordering, Little Endian or Big Endian. Mac machines use different from the PCs. You have to use byte sequences since they are universal. Thus, convert the data types to the expected amount of bytes in the order you think they should be and then the string should be zero terminated. I believe that the first two bytes (or four) of the structure are the size of the structure it self. So be carefull, because the server probably reads data in chunks of n (2 bytes), and then n bytes, then again n(2 bytes), and so on.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question