-
Socket Issue[Resolved]
VB Code:
Function IsServerOnline() As Long
Dim MySocket As Long
MySocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
Dim server As String
server = "66.66.66.66" ' example ip
[b]If (Connect(MySocket, server, Len(server))) = SOCKET_ERROR Then[/b]
MsgBox "Cannot Connect to Server", vbCritical, "Error"
Unload Me
End
IsServerOnline = 0
Else
MsgBox "Connected", vbInformation
End If
End Function
It errors "Type mismatch" on the bold line on "server"
What am I doing wrong? (yes I have the API's declared)
-
Re: Socket Issue
-
Re: Socket Issue
Post your declarations. That isn't the way to connect, unless I'm missing something.
-
Re: Socket Issue
Quote:
Originally Posted by dglienna
Post your declarations. That isn't the way to connect, unless I'm missing something.
He's using the API sockets... (but I have no clue how to use them)
Why not using the Winsock control ?
-
Re: Socket Issue
VB Code:
Public Declare Function Connect Lib "wsock32.dll" Alias "connect" (ByVal s As Long, addr As sockaddr, ByVal namelen As Long) As Long
I can't use the Winsock Control because my project is DLL. It errors "Out of Memory" in DLL. Thus the reason I use send/recv/connect/accept via the API's :)
Sorry it doesn't really error type mismatch but it errors "ByRef argument type mismatch".
Still haven't figured out the problem...
-
Re: Socket Issue
Right now you have:
VB Code:
Dim server As String
server = "66.66.66.66" ' example ip
server variable is a string, it has to be sockaddr type, as per your Connect declaration, that's why you get a "Type mismatch" error
-
Re: Socket Issue
VB Code:
Dim server As sockaddr
[b]server = "66.66.66.66"[/b]
Now it errors "Type mismatch" on the bold line.
-
Re: Socket Issue
Quote:
Originally Posted by Tantrum3k
I can't use the Winsock Control because my project is DLL. It errors "Out of Memory" in DLL. Thus the reason I use send/recv/connect/accept via the API's :)
I'm pretty sure it should work. You have to make an invisible form in your DLL project, and add the Winsock control on it. Then in the DLL, make a new instance of the form, and then you can use the Winsock control. I think I did it like this before, and it worked...
-
Re: Socket Issue
Quote:
Originally Posted by Tantrum3k
VB Code:
Dim server As sockaddr
[b]server = "66.66.66.66"[/b]
Now it errors "Type mismatch" on the bold line.
Well, of course sockaddr is not a string...
sockaddr is a Type, see what parameters sockaddr type takes... look in the MSDN how to use the sockaddr type...
-
Re: Socket Issue
Here, I did the research for you: MSDN - SOCKADDR
VB Code:
Public Type SOCKADDR
sin_family As Integer
sin_port As Integer
sin_addr As Long
sin_zero As String * 8
End Type
You have to convert your "66.66.66.66" address to a long, and pass it to sockaddr.sin_addr
I think there's an API function that converts the string address to long, but I don't remember which one.
But, since you know so little API programming, I REALLY suggest to you that you should find a way to get Winsock to work in your DLL, because you will have MUCH more head-ake (hmm... not sure how to spell that) if you continue on the API path.
-
Re: Socket Issue
I'll check that out.
Thanks.
I'll probably be back :D
-
Re: Socket Issue
Regarding to the post you edited :)
sockaddr.sin_addr = 66
sockaddr.sin_addr = 66 ' this just overides the previous 66, therefore you end up with 66 in the end, not "66.66.66.66"...
I did not test it, but I think this is the API that converts from string address to a Long
VB Code:
Public Declare Function inet_addr Lib "ws2_32.dll" (ByVal cp As String) As Long
EDIT, Here's the MSDN help for it MSDN - inet_addr
You have to use it like:
VB Code:
Dim server As sockaddr
server.sin_addr = inet_addr("66.66.66.66")
If (Connect(MySocket, server, Len(server))) = SOCKET_ERROR Then
'... the rest of the code
-
Re: Socket Issue
Also, in regards to the comment you made about puting the winsock control on a form hidden in your dll. I just did that it works fine without errors but when I try calling it in a Module like:
VB Code:
Dim ip As String
ip = Form1.Winsock1.LocalIP
MsgBox ip
It just exits the DLL. Closes it immediately without reason.
So I take it it's not going to happen, eh? :)
EDIT:
VB Code:
Dim server As sockaddr
server.sin_addr = inet_addr("66.66.66.66")
If (Connect(MySocket, server, Len(server))) = SOCKET_ERROR Then
Do you know how I can somehow put a port in there too for it to connect to also?
-
Re: Socket Issue
Quote:
Originally Posted by Tantrum3k
VB Code:
Dim ip As String
ip = Form1.Winsock1.LocalIP
MsgBox ip
Try without displaying the ip in the message box... a DLL is not supposed to have an interface, than's why I told you to make the form.Visible = False
Quote:
Originally Posted by Tantrum3k
Do you know how I can somehow put a port in there too for it to connect to also?
VB Code:
Dim server As sockaddr
server.sin_port = 80 ' or some other port...
-
Re: Socket Issue
you guys are too fast for me
VB Code:
Option Explicit
Private Type in_addr
S_un_b As Long
S_un_w As Long
S_addr As Long
End Type
Private Type sockaddr_in
sin_family As Integer 'Internet address family.
sin_port As Integer 'port number associated of the server
sin_addr As in_addr 'remote IP address of the server
sin_zero As String * 8
End Type
Private Declare Function Connect Lib "wsock32.dll" Alias "connect" ( _
ByVal s As Long, _
addr As sockaddr_in, _
ByVal namelen As Long _
) As Long
Private Const AF_INET = 2
Private Const SOCKET_ERROR = -1&
Private Declare Function inet_addr Lib "wsock32.dll" (ByVal ipAddres As String) As Long
Private Sub Command1_Click()
Debug.Print inet_addr("127.0.0.1")
Dim clientService As sockaddr_in
Dim MySocket As Long
clientService.sin_family = AF_INET
clientService.sin_addr.S_addr = inet_addr("127.0.0.1")
clientService.sin_port = [hl]htons(4500)[/hl]
If Connect(MySocket, clientService, LenB(clientService)) = SOCKET_ERROR Then
MsgBox "Cannot Connect to Server", vbCritical, "Error"
Unload Me
Else
MsgBox "Connected", vbInformation
End If
End Sub
-
Re: Socket Issue
I get this error now:
VB Code:
Dim listensock As sockaddr_in
Dim rc As Long
rc = listen([b]listensock[/b], 1)
Errors "Type mismatch" on the bold.
-
Re: Socket Issue
show me how you have declared everything so I can see what you've done wrong.
The listen function takes two longs.
-
1 Attachment(s)
Re: Socket Issue
-
Re: Socket Issue
SInce you have properly declared the listen function as having two long parameters, why did you try to pass it a parameter of type sockaddr_in?
Try something more like this
VB Code:
Sub main()
'Initialize Winsock
Dim mywsaData As WSAData
iResult = WSAStartup(MAKEWORD(2, 2), mywsaData)
If iResult <> NO_ERROR Then
MsgBox "Error at WSAStartup()"
Exit Sub
End If
'Create a SOCKET for listening for
'incoming connection requests.
Dim ListenSocket As Long
ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
If ListenSocket = INVALID_SOCKET Then
MsgBox "Error at socket(): " & CStr(WSAGetLastError())
WSACleanup
Exit Sub
End If
'The sockaddr_in structure specifies the address family,
'IP address, and port for the socket that is being bound.
Dim service As sockaddr_in
service.sin_family = AF_INET
service.sin_addr.s_addr = inet_addr("127.0.0.1")
service.sin_port = [hl]htons(4500)[/hl]
If bind(ListenSocket, service, LenB(service)) = SOCKET_ERROR Then
MsgBox "bind() failed."
Call closesocket(ListenSocket)
Exit Sub
End If
'Listen for incoming connection requests
'on the created socket
If listen(ListenSocket, 1) = SOCKET_ERROR Then
MsgBox "Error listening on socket."
Else
MsgBox "Listening on socket..."
End If
WSACleanup
End Sub
-
Re: Socket Issue
VB Code:
Dim service As sockaddr_in
service.sin_family = AF_INET
service.sin_addr.S_addr = inet_addr("66.66.66.66") 'example ip of the host computer
service.sin_port = 4500
If bind(ListenSocket, service, LenB(service)) = SOCKET_ERROR Then
MsgBox "bind() failed"
Call closesocket(ListenSocket)
Exit Sub
End If
It's erroring "bind() failed".
I used ShowErrorMessage(Err.LastDllError) and it says "Address already in use". I don't see how it can be since I have it set to my IP with port 4500.
-
Re: Socket Issue [Help Needed]
use "127.0.0.1" as your local IP address
if you still get an error call WSAGetLastError to get the error
-
Re: Socket Issue [Help Needed]
I tried 127.0.0.1 too but it still errors.
I also tried WSAGetLastError and it just says "0".
-
Re: Socket Issue [Help Needed]
what is ListenSocket equal to?
-
Re: Socket Issue [Help Needed]
I msgBox'd "ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)" and it said it's 148
-
Re: Socket Issue [Help Needed]
Try this project as is. Does it give an error?
-
Re: Socket Issue [Help Needed]
That works. Hmm, weird.
Thanks.
Now to Accept connections... ;)
I tried this:
VB Code:
Dim lngRetValue As Long
Dim lngBufferSize As Long
lngBufferSize = LenB(service)
lngRetValue = accept(ListenSocket, service, lngBufferSize)
If lngRetValue = SOCKET_ERROR Then
MsgBox "Error accepting connection"
WSACleanup
Call closesocket(ListenSocket)
End If
But it puts the application in "Not responding" and i have to close it.
I have all this listen, accept, socket, winsock - stuff in a Timer set to 1 millisecond. Should I have it in a timer or? What would you suggest I do?
-
Re: Socket Issue [Help Needed]
Here is one way to do it in a loop. You could use timer, but set interval to something like 50 or 100
VB Code:
'Create a SOCKET for accepting incoming requests.
Dim AcceptSocket As Long
Debug.Print "Waiting for client to connect..."
'Accept the connection.
While True
AcceptSocket = SOCKET_ERROR
While AcceptSocket = SOCKET_ERROR
AcceptSocket = accept(ListenSocket, 0, 0)
DoEvents
Wend
MsgBox "Client connected."
ListenSocket = AcceptSocket
Wend
WSACleanup
-
Re: Socket Issue [Help Needed]
Looping it doesn't seem to work. It doesn't do anything. I'm most likely doing it wrong so here's the code:
VB Code:
Dim lResult As Long
Dim mywsaData As WSAData
Dim blah As String
While True
blah = lResult <> NO_ERROR
While lResult <> NO_ERROR
lResult = WSAStartup(&H202, mywsaData)
DoEvents
Wend
Wend
Dim ListenSocket As Long
While True
ListenSocket = SOCKET_ERROR
While ListenSocket = SOCKET_ERROR
ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
DoEvents
Wend
Wend
Dim BindS As Long
Dim service As sockaddr_in
service.sin_family = AF_INET
service.sin_addr = inet_addr("127.0.0.1")
service.sin_port = 4500
While True
BindS = SOCKET_ERROR
While BindS = SOCKET_ERROR
BindS = bind(ListenSocket, service, LenB(service))
DoEvents
Wend
Wend
Dim ClientIp As sockaddr_in
Dim AcceptSocket As Long
Dim ClientIplen As Long
ClientIplen = Len(ClientIp)
While True
AcceptSocket = SOCKET_ERROR
While AcceptSocket = SOCKET_ERROR
AcceptSocket = accept(ListenSocket, ClientIp, ClientIplen)
DoEvents
Wend
ListenSocket = AcceptSocket
Wend
-
1 Attachment(s)
Re: Socket Issue [Help Needed]
Look at my code attached in the zip.
This is a DLL version of winsock. It's basically cSocket, with my own rapper around it.
It is used exactly like the winosck control is. Except you need to do:
VB Code:
Dim Woof As Socket
Set Woof = New Socket
'normal winsock code
Woka
-
Re: Socket Issue [Help Needed]
Wokawidget,
I tried using your Winsock dll code in my own DLL... it errored it saying "Failed to initialize 0x000000005" like that, someone told me that happened cuz winsock needs to create a window and it cant in a dll, or something, i woulda LOVED to use your winsock cuz its so easy and nice :D
Anyone see how I could be doing this wrong?
-
Re: Socket Issue [Help Needed]
first of all I wouldn't put the listen or bind functions in a loop
when you say it doesn't do anything, is it just waiting in the Accept loop?
Do you have a client trying to connect?
-
Re: Socket Issue [Help Needed]
I forgot to set it on Form_Load. But, now when I go to run the application it just hangs in processes and doesn't do anything. I even took bind and listen out of the loop but it still hangs and does nothing.
-
Re: Socket Issue [Help Needed]
go back to the code I posted above
-
Re: Socket Issue [Help Needed]
Your code works fine but I dont understand how the application will listen for incoming connections if it's not being looped. Ya know?
-
Re: Socket Issue [Help Needed]
it is being looped; the accept socket loop
-
Re: Socket Issue [Help Needed]
VB Code:
Dim MySocket As Long
Myocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
If MySocket = SOCKET_ERROR Then
MsgBox "error creating socket"
WSACleanup
End If
Dim clientService As sockaddr_in
clientService.sin_family = AF_INET
clientService.sin_addr.S_addr = inet_addr("66.66.66.66") 'connect to host ip
clientService.sin_port = 4500
If connect(MySocket, clientService, LenB(clientService)) = SOCKET_ERROR Then
MsgBox "Cannot Connect to Server", vbCritical, "Error"
LoginServer = 0
Else
MsgBox "Connected", vbInformation
End If
Even when the host is online it says "Cannot Connect to Server"....
.......
host listen function:
VB Code:
Dim ListenNow As Long
ListenNow = listen(ListenSocket, 1)
If ListenNow = SOCKET_ERROR Then
MsgBox "error in listen"
Call closesocket(ListenSocket)
WSACleanup
Else
MsgBox "listen done"
End If
accept function:
VB Code:
Dim CIp As sockaddr_in
Dim AcceptSocket As Long
Dim CIpLen As Long
CIpLen = Len(CIp)
While True
AcceptSocket = SOCKET_ERROR
While AcceptSocket = SOCKET_ERROR
AcceptSocket = accept(ListenSocket, CIp, CIpLen)
MsgBox "accept done"
DoEvents
Wend
ListenSocket = AcceptSocket
Wend
You see the problem?
-
Re: Socket Issue [Help Needed]
1. client. Are you sure you can connect to server? Did you do so using something like Winsock control as a test?
2. server: Don't put that msgbox in the accept loop
-
Re: Socket Issue [Help Needed]
I just tried connecting to the server via Winsock Control, still says Cannot connect even though the server is online.
-
Re: Socket Issue [Help Needed]
Do you have permission to connect to the server? What server are you trying to connect to?
-
Re: Socket Issue [Help Needed]
I'm trying to connect to my server made in vb and server uses winsock control to listen and accept .. but the client we're working on won't connect but another application that uses the winsock control to connect connects fine so it's something wrong with the code we're trying i think.
this is the connect code we talked about throughout this discussion:
VB Code:
Public Function LoginServer()
Dim GSSocket As Long
GSSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
If GSSocket = SOCKET_ERROR Then
MsgBox "error creating socket"
WSACleanup
End If
Dim server As sockaddr_in
server.sin_family = AF_INET
server.sin_addr.S_addr = inet_addr("66.66.66.66") ' servers ip
server.sin_port = 4500
If connect(GSSocket, server, LenB(server)) = SOCKET_ERROR Then
MsgBox "Cannot Connect to Server", vbCritical, "Error"
LoginServer = 0
Else
MsgBox "Connected", vbInformation
End If
End Function
-
Re: Socket Issue [Help Needed]
Are you sure the port is open on the server?
-
Re: Socket Issue [Help Needed]
-
Re: Socket Issue [Help Needed]
Sorry, there was a mistake in the code I presented.
Change this line
VB Code:
clientService.sin_port = htons(4500)
and you can add these right after as a check
VB Code:
If clientService.sin_port = INVALID_SOCKET Then
MsgBox "Invalid Port"
Exit Sub
End If
If clientService.sin_addr = INADDR_NONE Then
MsgBox "INVALID SOCKET"
Exit Sub
End If
-
Re: Socket Issue [Help Needed]
Still says "Cannot Connect to Server" when server is online.
-
1 Attachment(s)
Re: Socket Issue [Help Needed]
OK,
Here are two projects: one is a simple server built with Winsock control, the other is the client built with API.
Run the server, then the client, push the connect button on the client and it connects to the server. At least for me it did.
-
Re: Socket Issue [ Help Needed - again]
Ok works now.
Thanks alot moeur!
I appreciate all the help you have given me very much.
Now onto send ;)
VB Code:
Public Function sendmsg(ByVal s As Long, ByRef buf As Variant, ByVal buflen As Long, ByVal flags As Long) As Long
Dim out As Long
out = send(s, buf, buflen, flags)
sendmsg = out
End Function
And to use it:
VB Code:
Dim msg As String
msg = "testing"
sendmsg ConnectSocket, msg, Len(msg), 0
And on the Server side I have it in DataArrival:
VB Code:
Dim sData As String
tcpServer.GetData sData
Open "C:\msgtext.txt" For Output As #1
Print #1, sData
Close #1
Now, when I send the message via the sendmsg function - the server gets the data but it's all weird looking like this: "ôz { ZÂf¤ó"
I'm most likely doing it wrong like usual :rolleyes:
Any suggestions?
-
Re: Socket Issue [ Help Needed - again]
Don't use Variants or as Any.
VB Code:
Public Declare Function sendString _
Lib "ws2_32.dll" Alias "send" (ByVal s As Long, _
ByVal buf As String, _
ByVal buflen As Long, _
ByVal flags As Long) As Long
VB Code:
Dim bytesSent As Long
Dim sendbuf As String
sendbuf = Text1
bytesSent = sendString(ConnectSocket, sendbuf, Len(sendbuf), 0)
MsgBox "Bytes Sent: " & bytesSent
-
Re: Socket Issue [ Help Needed - again]
Ok that works. Thanks!
Now, one more problem left. Which is.. how would i publically declare this:
VB Code:
MySocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
Incase you don't understand what I mean I'll show you how it's done in C++:
Code:
SOCKET MySocket = NULL;
I need to do that in VB in global declarations at top of code, ya know? like this:
VB Code:
Dim MySocket As SOCKET ' globally declared
Private Sub DummyFunc()
' this does nothing Im just showing this as example
End Sub
So again all in all I want to do
SOCKET MySocket = NULL;
^ that in VB but I don't know how it's done.
Reason for this is because when I try to send messages using "send" it's not sending and working because it doesn't know the socket to send it through and in C++ SOCKT MySocket = NULL; declares it as the Socket (I think).
Like to send messages in C++:
Code:
int _sendmsg(SOCKET sock, char* buf, int len)
{
char* buffer = new char[len];
int msg = send(sock,buffer,len,0);
delete buffer;
return msg;
}
Like in the bold above .. notice how "sock" is declared as "SOCKET" and in vb it's "Long" .. why C++ it's declared, in my opinion, Properly as a socket so the "_sendmsg" function knows what socket to send it through.... and in vb it's just declared as a Long?. Anyway... I want to somehow (globally?) declare the Socket so I can send messages to the server without having to always connect and all that stuff more than once, if it's possible.
And in VB:
VB Code:
Function sendmsg(ByVal sock As Long, ByVal buf As String, ByVal buflen As Long) As Long
Dim msg As Long
msg = sendString(sock, buf, buflen,0) ' your sendString "send" function. can even be "send" yes
sendmsg = msg
End Function
See notice in C++ it's "SOCKET sock" and vb it's "sock As Long"
I hope you understand what I mean :sick:
-
Re: Socket Issue [ Help Needed - again]
There is no difference between Socket in C++ and Long in VB, so just declare it as long.
-
Re: Socket Issue [ Help Needed - again]
I tried doing that but when i try to send data it wont send anything.
I talked to a friend of mine that's good with C++ and he said "SOCKET MySocket;" gets the handle of your socket you created called "MySocket". So I need to know how to get the handle of my socket and global declare it. Like this:
VB Code:
Dim MySocket As FunctionToGetSocketHandle ' somehow
Now that's my next adventure :D
-
Re: Socket Issue [ Help Needed - again]
You declare MySocket globally as long.
You call the Socket function to set the value of MySocket to a valid socket.
Then you can use that value in any routine that wants a socket.
-
Re: Socket Issue [ Help Needed - again]
If you don't mind could you post an example?
I understand better seeing examples. Sorry :blush:
-
Re: Socket Issue [ Help Needed - again]
Maybe you should post what you are trying to do to make sure I understand.
-
Re: Socket Issue [ Help Needed - again]
I'm trying to do what you said :D
Quote:
You declare MySocket globally as long
I put this at top of coding page for global declare?:
VB Code:
Global ConnectSocket As Long
.................................
Quote:
You call the Socket function to set the value of MySocket to a valid socket
I done this:
VB Code:
Public Function IsServerOnline()
ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
If connect(ConnectSocket, service, lenB(service)) = SOCKET_ERROR Then
Msgbox "failed to connect"
End If
IsServerOnline = 1
End Function
I understand that yes - now here's my send function:
VB Code:
Public Function mysend(ByVal s As Long, ByVal buf As String, ByVal buflen As Long) As Long
Dim out As Long
out = sendString(s, buf, buflen, 0)
mysend = out
End Function
And to use it:
VB Code:
Private Sub Command1_Click()
Dim msg As String
msg = "testing"
mysend ConnectSocket, msg, Len(msg)
End Sub
See how it says "mysend ConnectSocket" ? well I don't understand how the mysend function knows what socket "ConnectSocket" is because the "ConnectSocket = socket(...,...,...)" is in the "IsServerOnline" function. You get what I mean? So I was told "SOCKET MySocket;" in C++ "SOCKET" gets the Handle to "MySocket" so you can use it anywhere in any function you want. I don't see how "Dim or Global ConnectSocket As Long" will get the handle of the socket since it's "Long" and C++ is "SOCKET". I know you said C++ SOCKET is same as Long in vb but it's just ... confusing and doesn't work for me. You understand what I'm trying to do? :sick:
-
Re: Socket Issue [ Help Needed - again]
The only thing that gets the handle to the socket is the socket function
VB Code:
ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
This is true in both C++ and VB. So you need to call this function before calling the SendString function.
-
Re: Socket Issue [ Help Needed - again]
So to just call it I put:
VB Code:
ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
in every function I want to send data?
-
Re: Socket Issue [ Help Needed - again]
No,
if you declare ConnectSocket as public, then it will always hold the handle to the socket so you only have to call socket once and connect once
-
Re: Socket Issue [ Help Needed - again]
VB Code:
Global or Dim ConnectSocket As Long ' globally declare it
Private Sub Command1_Click()
Dim msg As String
msg = "testing"
mysend ConnectSocket, msg, Len(msg)
End Sub
Public Function mysend(ByVal s As Long, ByVal buf As String, ByVal buflen As Long) As Long
Dim out As Long
out = sendString(s, buf, buflen, 0)
mysend = out
End Function
I tried doing this but it does't send anything :sick:
-
Re: Socket Issue [ Help Needed - again]
where do you run all that other code we talked about?
-
Re: Socket Issue [ Help Needed - again]
The WSAStartup stuff is in Sub Main() so it gets initialized at startup. And the socket an connect is in another function.
Here's an example of it:
VB Code:
Global ConnectSocket As Long
Sub Main() ' ive even tried puting this WSAStartup stuff with the socket function
Dim iResult As Long
Dim mywsaData As WSAData
iResult = WSAStartup(&H202, mywsaData)
If iResult <> NO_ERROR Then
MsgBox "Error at WSAStartup()"
End If
End Sub
Public Function IsServerOnline()
ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
If ConnectSocket = SOCKET_ERROR Then
MsgBox "Error at socket"
IsServerOnline = 0
End If
Dim service As sockaddr_in
service.sin_family = AF_INET
service.sin_addr = inet_addr("66.66.66.66")'server ip
service.sin_port = htons(4500)
If connect(ConnectSocket, server, LenB(server)) = SOCKET_ERROR Then
MsgBox "Failed to connect"
IsServerOnline = 0
End If
IsServerOnline = 1
End Function
Public Function mysend(ByVal s As Long, ByVal buf As String, ByVal buflen As Long) As Long
Dim out As Long
out = sendString(s, buf, buflen, 0)
mysend = out
End Function
Private Sub Command1_Click() ' just example
Dim msg as String
msg = "testing"
mysend ConnectSocket, msg, Len(msg)
End Sub
^ But when I try to send the message it doesn't send anything. It doesn't work :ehh: