Author | Message | Time |
---|---|---|
ntaryl | Hi and Good evening Iam here again and need some Help code a client server aplication and i try to use the socket api . not want the cSocketclass . Please small example client server with (connect,close,listen,send.recv )functions. thanks for the time | March 20, 2007, 7:05 PM |
MyStiCaL | uhm, so your asking for source, well www.pscode.com is your friend in that case. | March 20, 2007, 10:00 PM |
BreW | Well, ntaryl, I don't know of any good winsock object tutorials, but you can just use this: WS.State returns the state of the winsock's current connection. There are 10 possible states: [code] WinSock.State = sckClosed = 0 WinSock.State = sckOpen = 1 WinSock.State = sckListening = 2 WinSock.State = sckConnectionPending = 3 WinSock.State = sckResolvingHost = 4 WinSock.State = sckHostResolved = 5 WinSock.State = sckConnecting = 6 WinSock.State = sckConnected = 7 WinSock.State = sckClosing = 8 WinSock.State = sckError = 9 [/code] Self explanitory. What you want to do to create an outbound tcp connection is.... [code] WinSock.Close 'to rid it of any previous connection WinSock.Connect (STRING) ip address, (INT) porthere Private Sub WinSock_Connect() WinSock.SendData "meow mix r00lz" '(in string format) End Sub Private Sub WinSock_DataArrival(ByVal bytesTotal As Long) Dim Data As String WinSock.GetData Data MsgBox Data [/code] for a client side connection of some sort. for a server.... it's like this: [code] Private Sub Form_Load() WinSock.Close WinSock.Listen End Sub Private Sub Winsock_ConnectionRequest(ByVal RequestID As Long) Winsock.Close Winsock.Accept End Sub...... so on like that [/code] | March 20, 2007, 11:52 PM |
Hell-Lord | [code]Private Sub Winsock_ConnectionRequest(ByVal RequestID As Long) Winsock.Close Winsock.Accept End Sub...... so on like that[/code] You mean... [code] winsock.Accept RequestID[/code] and [code]Private Sub WinSock_DataArrival(ByVal bytesTotal As Long) Dim Data As String WinSock.GetData Data MsgBox Data [/code] do..... [code] Dim Data as String: Data = Empty [/code] | March 21, 2007, 4:32 AM |
BreW | [quote author=Hell-Lord link=topic=16511.msg166942#msg166942 date=1174451526] [code]Private Sub Winsock_ConnectionRequest(ByVal RequestID As Long) Winsock.Close Winsock.Accept End Sub...... so on like that[/code] You mean... [code] winsock.Accept RequestID[/code] and [code]Private Sub WinSock_DataArrival(ByVal bytesTotal As Long) Dim Data As String WinSock.GetData Data MsgBox Data [/code] do..... [code] Dim Data as String: Data = Empty [/code] [/quote] Oops @ the winsock.accept But why would I make my "Data = Empty"? That doesn't make sense, in vb6 all variables = 0 or otherwise null until given a set value. I can understand your reasoning if we were using C++.... | March 21, 2007, 2:16 PM |
l2k-Shadow | According to the topic, he was asking for winsock API, rather then the VB object. I'd suggest searching for CSocket on google. | March 21, 2007, 7:22 PM |
Hell-Lord | http://www.brutalnet.net/support/index.php?action=tpmod;dl=item26 There is the CSocket :) and @Brew i was told to do it that way without much reason but after the data has been set once how would it be cleared. | March 22, 2007, 12:25 AM |
MyStiCaL | maybe cuz he has it as DIM not STATIC? | March 22, 2007, 3:07 AM |
Hell-Lord | O sorry you should use "= VbNullString" . | March 23, 2007, 3:15 AM |
BreW | Speaking of vbNullString, what's really better? "" or vbNullString? Ofcourse vbNullString would be the obvious choice, but what about ""? "" is 5 bytes more, but it's faster (I have acually proven this) I made this one quick program where it joins byte arrays with either "" or vbNullString, suprise! 50000 concatinations of "l" with vbNullString took .4655 seconds where "" took acually .001 second less. And there's the third option: Declare a public variable "NulString" or w/e and make it = vbNullString on Form_Load. Good idea? Because the value for vbNullString (it's a constant) would already been picked up and assigned to NulString it would be much quicker then the normal vbNullString, while only taking up maybe 2 more bytes for storage, and maybe 1 per use. (note: I didn't try this but it sounds like a good idea...) | March 23, 2007, 8:11 PM |
Barabajagal | I don't think you're understanding something about vbNullString. It's an empty, null string. "" is not null. That's the difference. Yes, using "" within strings is faster, but when are you ever going to do that normally? you set vbNullString to a string variable to make it null, empty, and void of memory usage. | March 23, 2007, 8:19 PM |
BreW | [quote author=[RealityRipple] link=topic=16511.msg167125#msg167125 date=1174681192] I don't think you're understanding something about vbNullString. It's an empty, null string. "" is not null. That's the difference. Yes, using "" within strings is faster, but when are you ever going to do that normally? you set vbNullString to a string variable to make it null, empty, and void of memory usage. [/quote] A null string and empty string are different, for example, an empty string aka "" would take up 6 bytes in total: 4 for the length, and 2 for the null terminators. A nullstring is simply null, taking up zero bytes. Btw: I just realized that setting a variable = to vbNullString is the same as having a null string in the first place, except it doesn't have to keep processing it in the first place, and it doesn't make anything faster. *sigh* "Yes, using "" within strings is faster, but when are you ever going to do that normally?" Processor intensive programs? | March 23, 2007, 11:33 PM |
Barabajagal | uhm... a null terminator is one byte... 00. I asked when you're going to concatenate a string with "". The answer is never. | March 24, 2007, 4:01 AM |
Myndfyr | [quote author=brew link=topic=16511.msg167143#msg167143 date=1174692788] A null string and empty string are different, for example, an empty string aka "" would take up 6 bytes in total: 4 for the length, and 2 for the null terminators.[/quote] I'm relatively certain (though not 100%) that Visual Basic 6 strings are not Unicode. | March 24, 2007, 4:07 AM |
Barabajagal | They can be if you use StrConv on them, but otherwise, no, they're not unicode. | March 24, 2007, 4:17 AM |
raylu | In many scripting languages with no way to specify variable types, often, you need: [code]somevar = 5 somevar += ""[/code] to convert to a string. Also, using "" would cause the string literal to be created and destroyed every one of those 50,000 times, wouldn't it? | March 24, 2007, 6:13 AM |
l2k-Shadow | [quote author=[RealityRipple] link=topic=16511.msg167179#msg167179 date=1174709845] They can be if you use StrConv on them, but otherwise, no, they're not unicode. [/quote] Uhm.. VB6 strings are definitely stored in unicode, I've run into many problems when writing programs that use parts from different languages with VB6. But you can use this simple test too: [code] Sub Main() Dim s As String s = "Hello" MsgBox LenB(s) End Sub [/code] [quote author=[RealityRipple] link=topic=16234.msg164031#msg164031 date=1170661489] Ok, your grammar is lacking a bit there... So I'll try to answer what I think you asked. Yes, I paid $25 for Visual Basic 6 certification. Yes, it's pretty much a worthless feature nowadays (PRETTY MUCH doesn't mean totally useless). It's still there because there are uses for it. The fact is, it's there in (i think) all BASIC languages in some form. It's a handy time saver if you use it right. [/quote] Guess that VB6 certification was kinda shitty. | March 24, 2007, 4:53 PM |
BreW | [quote author=MyndFyre[vL] link=topic=16511.msg167177#msg167177 date=1174709228] I'm relatively certain (though not 100%) that Visual Basic 6 strings are not Unicode. [/quote] They are. Try this code... [code] Private Sub Form_Load() MsgBox LenB("asdf") End Sub [/code] 8? that must mean the characters must be two bytes each... Then the extra 6 for defining length and the scope of the string. What I'm trying to say is that vb6 strings are stored in unicode. EDIT*** oops.... shadow already posted this *hits his head off the wall* i should've read before i posted [quote author=raylu link=topic=16511.msg167192#msg167192 date=1174716805] Also, using "" would cause the string literal to be created and destroyed every one of those 50,000 times, wouldn't it? [/quote] This is correct, but acually it would be created and destroyed all 50,000 times. I'm unsure why, but it still seems to be faster then vbNullString even though using vbnullstring would indeed be the better choice. Perhaps a newer compiler for higher level languages might add some sort of catche for these type of operatons (of a commonly used string or value) and use that as a local variable instead.... just a guess | March 24, 2007, 7:21 PM |
Myndfyr | Oh hey, what do you know? | March 24, 2007, 7:26 PM |