Solved

Socket Communication Java to C

Posted on 1998-08-31
6
232 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
6 Comments
 

Author Comment

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

Expert Comment

by:sailwind
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Arumugam
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 2 41
Strange loading of website behaviour 3 22
eclipse java  build path 6 16
github account with ecipse 1 15
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now