java - Equivalent of DataOutputStream and DataInputStream in C -


i wrote code in java

public class client {     private static int    _port;     private static socket _socket;       public static void main(string[] args)     {          try         {             _port   = 8071;             _socket = new socket("localhost", _port);               random rand = new random();             int  n = rand.nextint(50) + 1;             dataoutputstream dos = new dataoutputstream(_socket.getoutputstream());                 dos.writeint(n);                 dos.flush();                // show server response             datainputstream din = new datainputstream(_socket.getinputstream());             int servernumber= din.readint();              system.out.println(servernumber);             string serverrandomstring=din.readutf();             system.out.println(serverrandomstring);               din.close();             dos.close();         } 

it's simple socket communication. server in java, want try writing client in c. there alternative dataoutputstream , datainputstream in c ?

the short answer: no, not really. sockets require more effort in c in modern languages. unfortunately there no "standard" socket library available [if you're writing cross platform app have compensate between differences too], , ones available aren't straight forward socket programming in java. you'll have start ground up, there plenty of c/c++ socket tutorials on web though. may find third-party library make easier. not trying discourage here, it's not hard figure out, it's remarkably easier in java.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -