开发者

UDP Socket programming in C++ in linux

开发者 https://www.devze.com 2023-03-14 17:20 出处:网络
I am completely new to socket programming and beginner-intermediate in c++. I have written a code in c++ and also another application in java. The java program will get data from the c++ code which ge

I am completely new to socket programming and beginner-intermediate in c++. I have written a code in c++ and also another application in java. The java program will get data from the c++ code which generates data in seconds. I am trying to use socket programming to transfer data between these two. I have found some code here: Socket programming tutorial. I am using开发者_JS百科 the UDP java client from it. However, for the UDP server it only has the C code. I need to embed this code into my C++ app. therefore I need a c++ version of it. Can anyone help me with this? or give me a link that gives a tutorial on it. anyhow the C code is:udpserver.c


You must declare addr_len as socklen_t, not int.


That is, the first few lines in main should read something like:

int sock;
int bytes_read; // <- note how this is now on its own line!
socklen_t addr_len; // <- and this too, with a different type.
char recv_data[1024];

... Leaving everything else as it were.

0

精彩评论

暂无评论...
验证码 换一张
取 消