posty68
June 5th, 2003, 04:44 AM
Hi
Can somebody explain sockets to me
and when they are used etc...
thanks
P
Can somebody explain sockets to me
and when they are used etc...
thanks
P
|
Click to See Complete Forum and Search --> : Sockets ?? posty68 June 5th, 2003, 04:44 AM Hi Can somebody explain sockets to me and when they are used etc... thanks P AlionSolutions June 5th, 2003, 04:52 AM Hi, big question... really big ;o) In general Sockets are endpoints for network-communication. There are two general types of sockets: Serversockets and Clientsockets. A serversocket waits for connecting client-sockets and client sockets connect to serversockets. there are some other "Layouts" but this is the most common. So now, what do you want to know else about sockets ? Greets Juergen posty68 June 5th, 2003, 04:55 AM So really they are used to help One product communicate with another over a Network ?? or is this communication with the OS ? Thanks J P AlionSolutions June 5th, 2003, 05:26 AM yeah, you got it ;o) you can write network-enabled applications such as database-clients and servers, chat-cliens and servers and so on. It is a really funny thing working with network-programming . For example: In an application you set up a socket calling the standard-library-call socket then you connect this socket using connect to some server, maybe a time-server which provides the current time. Now you have everything to never have manually set your system-time again. Of course you can connect your client to the port 80 of any webserver. As a result the webserver sends the HTML-indexpage to your clientsocket, from which you can read it into some window etc. If you choose to set up a server-socket, you can let it wait for connecting clients. That way you can code you own server of what kind ever. Who knows, maybe you code a good substitute for the Apache-Server *grin* Ok, any more questions ? Juergen posty68 June 5th, 2003, 05:29 AM Only one more Is there any good books which go into good details i should read ? Is it in the MSDN ? Thanks for all your help S Andreas Masur June 5th, 2003, 06:48 AM Winsock Programmer's FAQ (http://tangentsoft.net/wskfaq/)... Mathew Joy June 7th, 2003, 07:36 AM Originally posted by posty68 Only one more Is there any good books which go into good details i should read ? Is it in the MSDN ? I would suggest "Network programming for Windows" by Anthony Jones and Jim Ohlund. It explains winsock programming using APIs. dimm_coder June 7th, 2003, 08:28 AM The best choice is a Richard Stevens books :cool: Andreas Masur June 7th, 2003, 12:36 PM Originally posted by dimm_coder The best choice is a Richard Stevens books :cool: Despite his TCP/IP books aren't the others one related to UNIX network porgramming and API's... :confused: dimm_coder June 9th, 2003, 03:14 AM Originally posted by Andreas Masur Despite his TCP/IP books aren't the others one related to UNIX network porgramming and API's... :confused: Well, yeh... but hi has a good one which can be usefull for everyone "TCP/IP Illustrated" - a great book not about API's , but about TCP/IP protocols idiology :cool: neverthelees, I think that even "Network programming for Unix" can suggest many ideas for even Win sock programmers, because most concepts at least are the same :rolleyes: :cool: Andreas Masur June 9th, 2003, 01:07 PM Originally posted by dimm_coder neverthelees, I think that even "Network programming for Unix" can suggest many ideas for even Win sock programmers, because most concepts at least are the same :rolleyes: :cool: I will definitely not have any doubts about this... :cool: dimm_coder June 10th, 2003, 03:07 AM Originally posted by Andreas Masur I will definitely not have any doubts about this... :cool: Hmm, brrr ... Do U mean that U program for *nix systems? ... Andreas Masur June 10th, 2003, 08:25 AM Originally posted by dimm_coder Hmm, brrr ... Do U mean that U program for *nix systems? ... Unfortunately not at work...so it is more or less limited to my even less spare time... :cool: dimm_coder June 10th, 2003, 08:46 AM Originally posted by Andreas Masur Unfortunately not at work...so it is more or less limited to my even less spare time... :cool: Last year I have been programming for Linux at work. :cool: Some for Win ( during last autumn , but mostly for Linux). I write client/server apps, so I'm interesting in TCP/IP at all. Now I writing a filter for CommuniGate Pro (and || porting my Linux servers progect to FreeBSD). I always have been interesting in system programming, so at near time I want to learn Linux kernel drivers writting for ex. :cool: Also interested in OS'es internal structure and Linux for thouse purposes is the best arena for learning. What do U program for Linux at your free time? Andreas Masur June 10th, 2003, 11:49 AM Originally posted by dimm_coder What do U program for Linux at your free time? Well...unfortunately the last months (year) my spare time is pretty much near zero...thus I have not done much. Basically I used to look through some source code of the kernel for example...and I always wanted to start with GUI programming (KDE) but haven't really started yet... :eek: Nevertheless...we are getting way too off-topic here... :cool: dimm_coder June 10th, 2003, 11:57 AM Originally posted by Andreas Masur Nevertheless...we are getting way too off-topic here... :cool: Yeh, seems so. Nevertheless simply it was(/is) interest to talk with someone who has the same interests like U (I am - in this context) :rolleyes: :cool: SilentJackqh June 12th, 2003, 05:18 PM I try to want to create Socket, but I don't know how to fill Socket function parameter or WSA Socket function parameter. I try see In MSDN, but it's so little explaination about that. any suggestion for that ? SilentJackqh June 13th, 2003, 05:27 PM SOCKET JQSock; JQSock=socket(AF_INET,SOCK_STREAM,0); Why it's return INVALID_SOCKET ? I know the problem, I must call WSAStartup first. SilentJackqh June 14th, 2003, 01:13 PM I got another problem with bind function. is the network address should be the same as when I enter Network neighbourhood property IP Address, or I can type what ever I like ? Andreas Masur June 14th, 2003, 03:23 PM Originally posted by SilentJackqh I got another problem with bind function. is the network address should be the same as when I enter Network neighbourhood property IP Address, or I can type what ever I like ? Well..it should be a valid IP address of your machine...otherwise 'bind()' will not really do much... :cool: SilentJackqh June 14th, 2003, 03:36 PM What should I do if I setup my Networks with Obtain an IP address automatically ? SilentJackqh June 15th, 2003, 10:37 PM sockaddr JQSockAddr; JQSockAddr.sa_family=AF_INET; strcpy(JQSockAddr.sa_data,"1.1.1.1"); nError=bind(JQSock,&JQSockAddr,sizeof(JQSockAddr)); When I use WSAGetLastError() it's say that : The specified address is not a valid address for this machine. any suggestion ? SilentJackqh June 17th, 2003, 06:28 PM if finally can get IP Address by using gethostbyname function, but I have problem, when I used connect function my application can't do anything until it's connected, and when i used Recv function my app can't do anything until i someone sending message, is there anything I can do to make that never happen without create new thread ? is there anything I can do to see if there any message or not ? dimm_coder June 18th, 2003, 02:53 AM Read about select() function, async / nonblocking sockets . Amn June 18th, 2003, 09:33 AM For efficient client/server design implementation, use Overlapped I/O. Which is explained briefly through CreateFile/OpenFile/ReadFile//WriteFile WinAPI functions. Servers based on these APIs are FAR superior to the legacy socket servers when working with WINNT systems. SilentJackqh June 18th, 2003, 02:25 PM thanx I will try about a port, when I pick random port and used it in winsocket, can it recognise by client over internet link or I must register the port first somewhere ? SilentJackqh June 23rd, 2003, 05:44 PM What is port number in winsock for ? kaladorn July 4th, 2003, 12:41 AM Originally posted by Andreas Masur I will definitely not have any doubts about this... :cool: Concur. I've been a Senior Network Architect for a fledgling MMORPG, a wireless/wired comms gateway guy for public safety apps, and developed sockets code on every Win version, on OS2/Warp, and on several Unix and Linux variants and in QNX and I've taught TCP/IP Programming for the Internet at our local college. I've programmed sockets in C/C++/MFC(CSocket/Winsock) and in Java. I say all that by way of saying I've seen a fair few books and I'd have to recommend: TCP/IP Network Programming (2nd ed.) by Stevens The three volume series from Addison-Wesley(I think) by Douglas Comer (Book 1 is protocols, book 2 is programming sockets, and book 3 is some client-server design stuff IIRC) The former book is one all my students seemed to wish was their course book and we were programming on Windows. It has some good detailed information about the underlying structures mixed with some good information on how to program various aspects of sockets. Yes, it is oriented towards the standard sockets interface (BSD sockets). However, if you can understand that, you get the better basic understanding and CSocket or the other latter day Windoze innovations are fairly comprehensible. You don't have to use those classes - you can quite easily program from the basic socket libraries even in Windows. I actually prefer it. It does have some *nix specific stuff in it, but you can ignore that. In most texts, you are lucky if you get anything useful. In others, they have lots of useful info. Comer and Stevens both have written a fair few useful books (though some of the Windows oriented books may be good too - my worry here is people tend to learn those versions then they're scr*wed if they have to program in a POSIX or *NIX environment). So, I heartily recommend Comer, Stevens and the perusal of RFCs. They are free and they tell you the real story of the protocols that make the net run. Sockets are just a convenient way to manipulate them. :) Here endeth my soapbox session... kaladorn July 4th, 2003, 12:44 AM Originally posted by SilentJackqh SOCKET JQSock; JQSock=socket(AF_INET,SOCK_STREAM,0); Why it's return INVALID_SOCKET ? I know the problem, I must call WSAStartup first. That seems likely. You don't do that and you haven't initialized the Windows Socket architecture and it does need it. kaladorn July 4th, 2003, 12:56 AM Originally posted by SilentJackqh sockaddr JQSockAddr; JQSockAddr.sa_family=AF_INET; strcpy(JQSockAddr.sa_data,"1.1.1.1"); nError=bind(JQSock,&JQSockAddr,sizeof(JQSockAddr)); When I use WSAGetLastError() it's say that : The specified address is not a valid address for this machine. any suggestion ? Each network connection can be uniquely described by an n-tuple (in this case, a 5-tuple) that consists of protocol, local address, remote address, local port, remote port. From memory: The bind command is used on the socket to establish the local host and local port component of the 5-tuple. The socket call already established the protocol component. So you are attempting to bind the socket to a valid address. From the help files: If an application does not care what local address is assigned, specify the manifest constant value ADDR_ANY for the sa_data member of the name parameter. This allows the underlying service provider to use any appropriate network address, potentially simplifying application programming in the presence of multihomed hosts (that is, hosts that have more than one network interface and address). Note, on the client side if you bind they recommend you do not bind to any port other than 0. On the server side you may want to bind to other ports, but depending on your priveledges on the machine, some of those may fail. maron July 6th, 2003, 09:09 PM how to i get the server local IP address. my server now run in cmd > server.exe <IP> [Port] i wan it to be just > server [Port] codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |