×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Network Programming in C

Network Programming in C

Network Programming in C

(OP)
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.

RE: Network Programming in C

That is Standard with TCP/IP


hnd
hasso55@yahoo.com
 
 

RE: Network Programming in C

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
http://home.earthlink.net/~bobbitts

RE: Network Programming in C

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
 
 

RE: Network Programming in C

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
 
 

RE: Network Programming in C

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

RE: Network Programming in C

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
 
 

RE: Network Programming in C

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?

RE: Network Programming in C

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?

RE: Network Programming in C

perhaps you should shutdown the socket!

 

hnd
hasso55@yahoo.com
 
 

RE: Network Programming in C

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close