Solved

Socket Communication Java to C

Posted on 1998-08-31
6
241 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
Industry Leaders: 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

632 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