JNK
JNK

Reputation: 1753

C: UDP send & receive packets

I've been trying to use the socket() api in C but no luck so far. I would like to send a request to a specific device (Address: 192.168.2.55 Port: 12850) which will then return data to the application. How do I do this in C. I'm on a Mac so "the Unix way" if that differs from Windows...

Thanks and merry christmas!

Upvotes: 0

Views: 4998

Answers (2)

THE DOCTOR
THE DOCTOR

Reputation: 4555

The steps involved in establishing a socket on the client side are as follows:

  1. Create a socket with the socket() system call
  2. Connect the socket to the address of the server using the connect() system call
  3. Send and receive data. There are a number of ways to do this, but the simplest is to use the read() and write() system calls.

The steps involved in establishing a socket on the server side are as follows:

  1. Create a socket with the socket() system call
  2. Bind the socket to an address using the bind() system call. For a server socket on the Internet, an address consists of a port number on the host machine.
  3. Listen for connections with the listen() system call
  4. Accept a connection with the accept() system call. This call typically blocks until a client connects with the server.
  5. Send and receive data

Check to see if you have followed these steps thusfar with the code you have written.

Upvotes: 1

user502515
user502515

Reputation: 4464

For socket programming introduction, see http://beej.us/guide/bgnet/

Upvotes: 2

Related Questions