• Welcome to Valhalla Legends Archive.
 

Winsock api

Started by ntaryl, March 20, 2007, 02:05 PM

Previous topic - Next topic

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 

Code or Die 
Warez Lover For ever
Google my best Friend after JK

Mystical

uhm, so your asking for source,

well www.pscode.com is your friend in that case.

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:

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

Self explanitory.

What you want to do to create an outbound tcp connection is....

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

for a client side connection of some sort.
for a server.... it's like this:

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
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Hell-Lord

Private Sub Winsock_ConnectionRequest(ByVal RequestID As Long)
Winsock.Close
Winsock.Accept
End Sub...... so on like that


You mean...

winsock.Accept RequestID

and

Private Sub WinSock_DataArrival(ByVal bytesTotal As Long)
Dim Data As String
WinSock.GetData Data
MsgBox Data


do.....
Dim Data as String: Data = Empty

brew

Quote from: Hell-Lord on March 20, 2007, 11:32 PM
Private Sub Winsock_ConnectionRequest(ByVal RequestID As Long)
Winsock.Close
Winsock.Accept
End Sub...... so on like that


You mean...

winsock.Accept RequestID

and

Private Sub WinSock_DataArrival(ByVal bytesTotal As Long)
Dim Data As String
WinSock.GetData Data
MsgBox Data


do.....
Dim Data as String: Data = Empty
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++....
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

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.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

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.


Mystical

maybe cuz he has it as DIM not STATIC?

Hell-Lord

#8
O sorry you should use "= VbNullString" .

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...)
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

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.

brew

#11
Quote from: [RealityRipple] on March 23, 2007, 03:19 PM
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.
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?
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Barabajagal

uhm... a null terminator is one byte... 00.
I asked when you're going to concatenate a string with "". The answer is never.

MyndFyre

Quote from: brew on March 23, 2007, 06:33 PM
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.
I'm relatively certain (though not 100%) that Visual Basic 6 strings are not Unicode.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Barabajagal

They can be if you use StrConv on them, but otherwise, no, they're not unicode.