IRC Networks
Irc Logs Stats
Start date: 2007-09-27 02:48:27
Last update: 2008-10-24 20:19:38
Channels: 41
Logged Lines: 6230436
Size: 1825.68 MB
Powered by
Channel Info
Network: freenodeChannel: #csharp |
Search in www.irclog.org
Log from #csharp at freenode 2006-07-31
[12:42]<sz2yzgrzz>http://msdn2.microsoft.com/en-us/library/system.net.sockets.socket.poll.aspx
[12:43]<rdyvv>but the object doesnt exist when i do Socket.Poll thats why im trying to create it at construction
[12:43]<sz2yzgrzz>of course not
[12:43]<sz2yzgrzz>are you listening for incoming sockets
[12:43]<sz2yzgrzz>what are you doing
[12:44]<lcs>amitt: have you ever been programming sockets (in any language)?
[12:46]<rdyvv>i have something like: void Connect() { tcpListener.Start(); socketForClient = tcpListener.AcceptSocket(); ... } and i want to check if thers already a connection before i do that.
[12:46]<rdyvv>pks: no i havent. first steps
[12:46]<lcs>tcpListener does not connect
[12:46]<lcs>it accepts incomiing connections
[12:47]<lcs>do you want to connect to some specific place (like irc server, web server, mail server) or accept connections from other places (other word to be a server)?
[12:47]<rdyvv>is it wrong to call it actions of connection?
[12:47]<lcs>words*
[12:47]<rdyvv>to be the server
[12:47]<rdyvv>to read from a stream
[12:48]<sz2yzgrzz>then create a socket and call listen
[12:48]<rdyvv>create it at construction?
[12:48]<sz2yzgrzz>create socket, specify address/port, bind socket, listen
[12:49]<lcs>mhm
[12:49]<sz2yzgrzz>what does that statement mean "at construction"
[12:49]<lcs>http://www.java2s.com/Code/CSharp/Network/SimpleTcpServer.htm
[12:49]<lcs>here is an example
[12:49]<sz2yzgrzz>http://msdn2.microsoft.com/en-us/library/system.net.sockets.socket.listen.aspx
[12:49]<sz2yzgrzz>its also documented in msdn
[12:50]<rdyvv>at the construction of my object app which is called ChatServer
[12:50]<sz2yzgrzz>just need to learn how to use it
[12:50]<rdyvv>im checking the example
[12:50]<lcs>http://www.java2s.com/Code/CSharp/Network/TCP-Server.htm
[12:50]<lcs>here you have examples of many other servers
[12:50]<lcs>like, the ones that use poll, select
[12:50]<lcs>to handle multiple clients in one thread
[12:50]<sz2yzgrzz>non blocking io :)
[12:51]<sz2yzgrzz>sucks to do in java
[12:51]<rdyvv>and that will solve how to check if there's already a connection active before trying to conncet?
[12:51]<cjmgrug>asynchronous??
[12:51]<sz2yzgrzz>??
[12:51]<lcs>amitt: what?
[12:52]<sz2yzgrzz>you will get an exception if it cannot bind to the port/address
[12:52]<wgzmgr>au revoir
[12:52]<rdyvv>pks: my problem is how to check if there is already a connection before attempting to conncet. im asking if these examples contain a solution to that
[12:53]<sz2yzgrzz>you will get an exception if it cannot bind to the port/address
[12:53]<lcs>amitt: you can (should) make a list of all outbound connections you make
[12:53]<lcs>amitt: and if theList.Count > 0, then you will know that you are connected :)
[12:53]<lcs>amitt: but still, i dont understand your problem
[12:53]<sdnffdxdlld>amitt: you mean you want to stop multiple connections from the same IP?
[12:54]<sz2yzgrzz>amitt just doesn't understand the socket concept
[12:54]<sz2yzgrzz>maybe not even the networking concept
[12:54]<rdyvv>smellyhippy, no.
[12:54]<lcs>amitt: tell us what do you want to do, skip the 'how' part
[12:54]<rdyvv>sabiancra, you're right thats waht im learning right now. but i do understand the networking concept
[12:55]<rdyvv>pks: im trying to do a simple chat. i have a chat server and a chat client
[12:55]<sz2yzgrzz>focus on the chat server first
[12:55]<sz2yzgrzz>use telnet to test it
[12:56]<rdyvv>the server has a button called "listen for conncetion" and "disconncet"
[12:56]<lcs>mhm
[12:56]<lcs>what for do you need to check if there is connection or not?
[12:57]<rdyvv>pks: what if the user presses listen after someone has already conncted?
[12:57]<lcs>user does not press listen
[12:57]<lcs>user = client?
[12:58]<lcs>i think, that there should not be any listening socket created before anyone presses listen button
[12:58]<rdyvv>user = the person using the chatServer app. i want to give the ability to listen and not listen
[12:59]<sz2yzgrzz>there will be an exception thrown
[12:59]<sz2yzgrzz>you can only bind once to a unique address/port combination
[12:59]<sdnffdxdlld>amitt: how about button.Enable = False; when they click the listen button, then they can't click it
[12:59]<lcs>ListenButton_onCliick(....) { if(listenSocket == null) { listenSocket = new ..... } }
[12:59]<lcs>thats all
[13:00]<lcs>StopListenBurron_onClick() { if(listenSocket != null) { listenSocket.Close(); listenSocket = null; } }
[13:00]<sz2yzgrzz>wrap the listen in a try/catch in addition to that
[13:00]<sz2yzgrzz>in case another app is binding to that port
[13:00]<lcs>and you dont have to worry that some will press listen, stop listen too many times
[13:01]<lcs>mhm, true, try and catch are usefull there
[13:01]<sz2yzgrzz>and checking if the socket is null is a crappy way to check the state of the socket
[13:01]<rdyvv>pks: ur not using TcpListener?
[13:02]<lcs>nope
[13:02]<sz2yzgrzz>System.Net.Socket
[13:02]<lcs>i've never been listening to sockets in c#/.net, but i've done that in C
[13:02]<lcs>the concept is the same
[13:02]<sz2yzgrzz>yep
[13:03]<sz2yzgrzz>a socket is a socket
[13:03]<lcs>except that in .net you dont have to worry about buffering not writen data
[13:04]<cjmgrug>its for these reasons i loiter around this channel.. a chance to read great thoughts by great people.." a socket is a socket " - sabiancra, 2006
[13:04]<lcs>hahaha ;p
[13:04]<cjmgrug>ok i'm just bored :p
[13:05]<sz2yzgrzz>like you have never heard that phrase before
[13:05]<rdyvv>so how do you implement: socket = tcpListener.AcceptSocket() ?
[13:05]<lcs>CodeRun: n/p, were are borded too, otherwise i wont be sitting here
[13:05]<sz2yzgrzz>i cannot sleep
[13:05]<sz2yzgrzz>and i have to work in an hour
[13:05]<sz2yzgrzz>so i am killing time
[13:05]<lcs>i am at work
[13:05]<lcs>;p
[13:05]<sz2yzgrzz>i do nothing at work
[13:05]<sz2yzgrzz>its really quite pointless
[13:06]<cjmgrug>sometimes i wonder, insomnia can be so advantageous..
[13:06]<lcs>amitt: Socket main = new Socket(address, port, tcp, etcc....);
[13:06]<lcs>amitt: main.Bind(); main.Listen();
[13:06]<sz2yzgrzz>i wrote a ansyncronous chat server in java using NIO during my long periods of boredom at work
[13:07]<lcs>amitt: now, to accept connections do: while(true) { Socket newConn = main.Accept(); }
[13:07]<cjmgrug>how many hours per day, do you all sleep?
[13:07]<sz2yzgrzz>about 5-8 during the summer







