Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Network Programming in C

Status
Not open for further replies.

Ajay77

Programmer
Nov 8, 2000
1
GB
Does anyone know or have any programs that do the following:

- A Client writes and reads to a flat file from a Server.
- The Server must send acknowledgements and each packet must be sequenced.
 
That is Standard with TCP/IP


hnd
hasso55@yahoo.com

 
You shouldn't have to worry about the 2nd part of your questions as this is, indeed, handled by TCP/IP.

The first part could be done a number of ways depending on your server configuration. One way is to use HTTP to read the file and FTP to write the file which would involve sockets. You could also set up NFS on the server, export the relevant file systems and then mount them on the client which would be simpler and would only involve basic file i/o.

You don't mention what platform the client program will run on. If it's a flavor of UNIX, check out UNIX Network Programming by W. Richard Stevens for good explanations and examples of sockets programming.

Barring that, do a web search for "sockets," "network programming," and/or "winsock programming" (if you're writing it for Windows).

HTH,

Russ
bobbitts@hotmail.com
 
I know these books.
If you want to write Software for that Problem: I have posted some examples in July in the Forum.

If I Remember correct the Thread was posted by Trainlogan.
The Forum was c or c++ ???

There is no big difference between Berkley Socket or Winsock programming.



hnd
hasso55@yahoo.com

 
Ok. I checked it.

on 29th July there is a thread in the Borland C++ Forum posted by trainlogan with two examples (One Server, One Client) for Windows NT/9x

hnd
hasso55@yahoo.com

 
My question is:
Is there a function in C, that can read the date(last modified, Last accessed, and last accessed) and length of a file.
I know length is easy, point the pointer to the end of the file and the return value is the length. But is there a function to realize this?

Thanks
 
That is a question of the operating system. With windows you could use the function ftime with UNIX I am not shure i will have a look.

hnd
hasso55@yahoo.com

 
Thanks Rbobbit.
I solved this problem using stat(), it not only can read the last update time but also last modified time and length.

Now I have another problem.
I run a server in an eternal loop.
I need to close the socket after I press ^c, so I use

signal(SIGTERM,cleanEXIT);
signal(SIGINT,cleanEXIT);

Then in the top of the program.
I use :

int listenfd;

void cleanEXIT()
{
close(listenfd);
/* clean up the garbage processes*/
while(waitpid(-1,NULL,WNOHANG)>0);
printf("Byebye");
exit(0);
}

But the problem is the the socket "listenfd" did not close.
I define listenfd as a global variable.
when I open it ,as :
ptnb=atoi(argv[1]);

listenfd=socket(AF_INET,SOCK_STREAM,0);

What is wrong with my program?
 
I used setsockopt() in the program, but it does not work either?

On the server side:

I used setsockopt before I bind() listenfd to the serversocket.

But after clients requested, then exit and the server responses, then exit. The socket still does not released.

Why is that happen?
 
perhaps you should shutdown the socket!



hnd
hasso55@yahoo.com

 
Yes, I find the answer, Setsockopt can ONLY be used before bind, If after bind, the socket will not release the port after close.

I met a new problem here: when I compile the program, I find
the following error. What does it mean?

Undefined first referenced
symbol in file
gethostbyname /var/tmp/ccV065JB.o (symbol belongs to impl
icit dependency /usr/lib/libnsl.so.1)
inet_ntoa /var/tmp/ccV065JB.o (symbol belongs to impl
icit dependency /usr/lib/libnsl.so.1)
ld: fatal: Symbol referencing errors. No output written to se
collect2: ld returned 1 exit status


I have included all the .h files I believe is necessary.
What is the possibility of this problem.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top