Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!think.com!zaphod.mps.ohio-state.edu!caen!uflorida!crane.cis.ufl.edu!leh From: leh@crane.cis.ufl.edu (Les Hill) Newsgroups: comp.unix.programmer Subject: Re: More questions on sockets Message-ID: <29187@uflorida.cis.ufl.EDU> Date: 14 Jun 91 18:51:49 GMT References: <1991Jun14.162215.14657@ncsu.edu> Sender: news@uflorida.cis.ufl.EDU Reply-To: leh@crane.cis.ufl.edu (Les Hill) Organization: U of Florida. Computer Science Dept. Lines: 53 In article <1991Jun14.162215.14657@ncsu.edu>, jwb@cepmax.ncsu.edu (John W. Baugh Jr.) writes: |> - when trying to bind a stream socket I sometimes get an error |> "Address already in use", even though I've closed the socket |> (for example, when I run the program in succession a couple of |> times). Is there something else I have to do? I believe this is a problem due to TCP's "handshaking" on a close. One workaround I use is: ... int slin = 0; /* unset SO_LINGER */ ... /* unset SO_LINGER */ if (setsockopt(socket, SOL_SOCKET, SO_LINGER, (char *)&slin, sizeof(int)) < 0) { #ifdef DEBUG perror("setsockopts:SO_LINGER"); #endif return -1; } ... when I am setting up the socket for use. |> - assuming I'm on the right track (big assumption), is it possible |> to raise the level of abstraction of my send_msg/recv_msg |> functions. For example, ideally one would like to do the |> following: |> send_msg(char *msg, int size, int process); |> recv_msg(char *msg, int size, int process); |> where "process" may be a process on any machine. Okay, so that's |> probably asking too much. What I currently have is: |> send_msg(char *msg, int size, char *hostname, int port); |> recv_msg(char *msg, int size, int port); |> Can one do better (w/o an inordinate effort)? Probably not. In order to achieve the functionality you want in your ideal situation, you (IMHO) will need to implement your own "protocol" on top of TCP. The "protocol" could get arbitrarily complex -- as an example, I wrote a "sockets library" that allowed dynamic link management, while maintaining a fairly high level interface (e.g. extern int WriteConnection(); /* (char *data, int size, int user) */ extern void ReadConnection(); /* (char *data, int (*func)()) */ ) -- the "protocol" I implemeted was about 3K lines worth of nicely formatted (and probably bloated :) code. Les -- Extraordinary crimes against the people and the state have to be avenged by agents extraordinary. Two such people are John Steed -- top professional, and his partner, Emma Peel -- talented amateur; otherwise known as "The Avengers." INTERNET: leh@ufl.edu UUCP: ...!gatech!uflorida!leh BITNET: vishnu@UFPINE