C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-15-2009, 11:26 AM   #1
Registered User
 
Join Date: Oct 2008
Posts: 66
Socket Programming in C

Trying to program a stop and wait network protocol in C which will send a packet in the form of a struct

Code:
struct MyHdr{
	unsigned char seq;  //sequence number
	unsigned char wndwsize;  //size of the send window
	unsigned char pcktsize;   //packet size
	data char[sizeof pcktsize];    //data array size of packetsize (-overhead)
};
I have been reading up on the send() and recv() classes but still don't have enough knowledge to know how to send a "packet" over. Can someone clarify how to do this with me?

Here's what I have been playing with

Code:
	

while(fread(buffer,1,64,in) !=0){
		struct MyHdr packet;
		
		resent =0;
		count++;
		
		packet.pcktsize = buffer;//copy buffer into our packet 64bytes
		packet.seq = count;
		packet.wndwsize = count;
		
		do
		{
		//something with a CRC
		//
		}

		send(sockfd,packet);

	}
Can I just send with the given socket and the packet? Also how would I receive it?
TaiL is offline  
Old 07-15-2009, 11:46 AM   #2
Registered User
 
Join Date: Oct 2008
Posts: 66
can someone move this to the C programming forum?
TaiL is offline  
Old 07-15-2009, 01:03 PM   #3
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
Quote:
Originally Posted by TaiL View Post
I have been reading up on the send() and recv() classes but still don't have enough knowledge to know how to send a "packet" over. Can someone clarify how to do this with me?
They are not classes. They are functions.

Before you can do something special in the way that you want it, you may have to be able to do something normal and basic. So trying going through a simple socket/networking tutorial and write a simple client and server program or something. They use send and recv. Then you will have the understanding you need to proceed onto constructing, transmitting, and deconstructing packets.

Right now, you do not have this basic understanding, so there is not much that can be said, I think.
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is offline  
Old 07-16-2009, 09:14 AM   #4
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 2,845
You do not need to worry about the header portion of the packet; this will be done for you. All you need to worry about is the packet payload (the data you are sending and receiving).

In other words, something like this is perfectly valid:
Code:
send(fd, "here is some data", 18, 0);
From your code, it's clear that you need to read the documentation on the send() function. You do not need to worry about CRCs, sequence numbers, or window sizes.
bithub is offline  
Old 08-04-2009, 03:35 AM   #5
Registered User
 
Join Date: Aug 2009
Posts: 2
writing dhcp client using sockets

Hi all,

Can anybody give me a guideline for writing a DHCP client using socket programming on Linux platform?

Any kind of help, suggestion of good books and links will be highly appreciated ...

Thanks and regards,
Dash
dash is offline  
Old 08-22-2009, 11:12 PM   #6
Registered User
 
Join Date: Aug 2009
Posts: 1
netlink sockets..

what are netlink sockets. When and why they are used.
Maniraj Patri is offline  
Old 08-23-2009, 12:19 AM   #7
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
"me too" bumpers should start a new thread.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline  
Closed Thread

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
socket programming question, closing sockets... ursula Networking/Device Communication 2 05-31-2009 05:17 PM
Socket Help - Multiple Clients project95talon C Programming 5 11-17-2005 02:51 AM
socket programming in linux crazeinc C Programming 1 05-27-2005 07:40 PM
when to close a socket Wisefool Networking/Device Communication 5 11-02-2003 10:33 AM
socket newbie, losing a few chars from server to client registering Linux Programming 2 06-07-2003 11:48 AM


All times are GMT -6. The time now is 04:27 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22