Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Socket Connection


First let me explain my program.

Its a instant messenging program like AOL or MSN how ever you wanna look at it. It runs off a server / client base system and is working pretty much so far. Except for one problem with a socket connection.

When the server is started it is ready to accept connections using a socket index.

When you open a client, the client will load to a login form. In the form_load, the login will connect to the server automaticly as soon as it is started.

The server will get the connection and say that it is connected. Then a second later it will say the clients connection is closed.

But, on the client, if you open the 'Register New Screen Name' window (which will disable the login screen, close any open sockets on it, and load the register window), and then close the register window, (Which will enable the login window again, and reconnect socket(0)), it will connect to the server again and the connection wont get kicked / closed.

Is there a reason why this is happening?

I dont have any other problems with the server or the client. Just this little problem when the client is first started.

Any help will be appreciated. Thanks.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Socket Connection
Hi ,

Can anyone help me with the code for a TCP/IP connection to a server?
I know the host and port, but how do I do it in VB??Please advice ...

Cant Accept Connection From New Socket
Greetings,
What's wrong with my code here?
It keeps accepting connection on the listening socket (Winsock1(0).LocalPort = 11000).

Code:
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Randomize
If Index <> 0 Then
Winsock1(Index).Close
Else
Load Winsock1(Winsock1.UBound + 1)
With Winsock1(Winsock1.UBound)
.LocalPort = Int(Rnd() * 10000) + 12000
.Close
.Accept requestID
End With
End If
End Sub

Thanks in advance for your help

Regards,


Joe

Pass Socket Connection To Another App?
Is it possible to open a socket connection in one program and then have another program use that connection. I would like to be able to launch another app that uses the connection made in the calling app.

Thanks..

How To Close A Socket Connection?
Hi Gurus,
I have a question on how vb's socket operation. The scenario is like:

Code:

' open connection
client = TcpClient(ip, port)
...
' close connection
client.close()


After connection set up, I can see an established connection using netstat besides the server's listening port.

Code:

TCP 0.0.0.0:9500 0.0.0.0:0 LISTENING
TCP 127.0.0.1:9500 127.0.0.1:1378 ESTABLISHED

"9500" is the server's listening port. My server is running on the same machine with my client.

I've thought after close(), the established connection should be removed. However, nothing changes.

Then, after I close the client app, the connection turns into,

Code:

TCP 127.0.0.1:1378 127.0.0.1:9500 TIME_WAIT


Hmm... I know little about what the status should be in response to vb's socket operation. Is this normal? Thank you.

File Transfer Using Socket Connection
How do i open up a file bit-by-bit, send it over a socket connection and resave it bit-by-bit.

Everything i have done in the past is with ascii codes, i have never worked at the binary level

Failed To Close Socket Connection
hi,

i am using a Winsock control in my application.
i wrote some lines of code in the Close event of the control but when i activate the Close function it doesn't close the connection and dont get into the Close event.

is that a common problem? any idea how to solve it?

thank,
ohad.

VB 2005 Help Please! - Socket Connection To Serial Device
Hi Everyone.

I am an experienced VB2-6 programmer who has just - due to a project to be deployed on PDAs - upgraded to VB 2005. And I'm floundering.

I have a specific problem which I urgently need to fix and would greatly appreciate any help....

I have a PDA (running Windows Mobile OS 2003) which must listen for strings from a weighing scale and then send ACk/NAK charcaters back to it. I can easily see the strings if I connect via Hyperterminal and so I know they are being sent out.

In VB6 with the Winsock control this was easy. I set the controls RemoteAddress and RemotePort, connected and simply waited for data to arrive in the Connect request / dataArrival sub routines.

I have tried all sorts of VB 2005 examples on remorting (TCPListener, etc), but that appears to need BOTH ends to be Running the .NET compact frame work.

Does anyone PLEASE have any ideas or preferably a bit of sample code on how to recognise the string data in the PDA application?
Thanks in advance for any help,

Malcolm

Matching A Socket Array Number And A A Connection Using Winsock
I'm trying to keep track of a socket array number and the pc that initiated the connection. I'm using Winsock to communicate with up to 30 remote pc's and have to be able to send data at will to pc's. As my code currently stands, pc's connecting with the server all use a certain socket array number. The problem is when I want to link one of these sockets back with the pc's that opened it, my app behaves abnormally as it always uses the first socket that was created.
I have tried linking a socket with the remote host from the server using RemoteHost but this method won't show up the remote host.

Basically, I know the socket array number, so, how can I go back to the host that created it ?

I have read the threads here, but I coul not find any firm reply on this specific issue.

Any help, please ?

Greatly appreciated.

Mike

How To Create Voice Chat Application With UDP Socket Connection
i want to create a voice chat application with UDP socket connection. can anyone help me out with proper explanation and code?

Using Socket In VB6
I m currently developing a project to enable 2 client computers to communicate through voice and exchanging data. I think i am suppose to use socket to achieve the above function. Am i right? However i have no idea on how to do it. Wonder anyone out there can help me up

Socket Help
im going to try to make a messaging program, ive downloaded sum source codes for a couple and i see that they all use a socket, if someone could explin to me what purpose they serve or show me a site that talks about em i'll appreciate it

Vb Socket Help
Hi, I am having a problem with my socket I am creating, I get a perfect connection if my Server is in ipv4 format but not when I have the host name (Ex. www.google.com) Think you can give me a hand?

This is how I tell if it's an ipv4 or not:


Code:
SocketAddress.sin_family = AF_INET
If IsNumeric(Right(Server, 1)) Then
SocketAddress.sin_addr = inet_addr(Server)
Else
SocketAddress.sin_addr = gethostbyname(Server)
End If

I Need A Help For Udp Socket
hi, my modem is blocking to UDP port and then Why I can't get ansver over the internet. how can I do transfer with Camfrog UDP. Can you help me please?

netstat -ano command results:

Quote:




UDP 0.0.0.0:1460 *:* 4036
UDP 0.0.0.0:1461 *:* 4036
UDP 0.0.0.0:1462 *:* 4036






netstat -ab command results:
UDP

Quote:




UDP vivaldi:1460 *:* 4036
[Camfrog Video Chat.exe]

UDP vivaldi:1461 *:* 4036
[Camfrog Video Chat.exe]

UDP vivaldi:1462 *:* 4036
[Camfrog Video Chat.exe]






TCP

Quote:




TCP vivaldi:1458 host02.cam.jvs.qwest.net:2138 ESTABLISHED 4036
[Camfrog Video Chat.exe]

TCP vivaldi:1459 207.226.22.156:6003 ESTABLISHED 4036
[Camfrog Video Chat.exe]






I can't get data without open data by modem. but I can't tell evryone hwo is the program user . can you open a port ?


help me please... thanks a million...

Need Help With Socket Again!
I want to code a socket class which supports indexes like Winsock
did in 6.0. How can I manage that if I am not allowed to use
arrays? I get a: "WithEvents variable cannot be typed as arrays".

I'm so ****ing desperated with this problem, if someone can
help me it would be really great.

I will include that guy into my developer list of my client to
(once it is .NET, currently its 6.0)

Yeah I'm using .NET

Socket Used More Than Once?
Hey! I'm writing a program that will host your files publicly over
the internet. However, i am having trouble figuring out how to
make an array of WinSock controls accept connections, when the
default port on any HTTP server is 80... i need help.

It dosen't add up. If i need multiple users to be able to visit my
site at once, then i need to use a different port for each WinSock
control, but if i use a different port for each one, it wont connect,
knowing the browser assumes the port is 80...

I need help, as said before. Can anybody help me in the
predicimant?

Socket
Hi,

I used client and server form in my application. Both forms has socket controls. If i use two command buttons for connect and send, it's working nicely. I used :



Private Sub cmdConnect_Click()
    tcpClient.Connect
End Sub

Private Sub cmdSend_Click()
    tcpClient.senddata txtSend.text
End Sub

Instead of the above code, if i use the both in the same command, it shows error.



Private Sub cmdSend_Click()
    tcpClient.Connect
    tcpClient.senddata txtSend.text
End Sub

Plz. help me to resolve this pbm (becuase i should not used two command buttons in my form and connection is required for each send according to the ip selection in the list box )

Transfer A DC Through A Socket
I want to send a DC (graphic) from one machine to another machine through sockets.

Socket Programming
Hi Friends!!

Between a client and server i am using sockets to transfer data
The sockets uses CSocket class available on internet.
Stream of data is transferred from server to the client continously
but i have found that some substrings goes missing when the data reaches the client...I am using TCP protocol, which ensures that there is no data loss,
I am not able to figure out the problem

Please help!!


Thanx

Regards

Mustafa

Socket Communication With Php
how can i send data to a php file with sockets?

I have the php file in the web server...i connect to the web server...then what should i write?

Socket Problem
I'm having a problem either connecting or sending/receiving data with my 2 programs (I'm not sure which). I don't have an array of sockets because I only want to accept 1 connection and communicate back and forth on one connection. I'm also using SocketWrench, not WinSock.

Here's the code for the "server":

Code:
Private Sub Socket1_Read(DataLength As Integer, IsUrgent As Integer)
Socket1.RecvLen = DataLength
Text1.Text = Socket1.RecvData
End Sub


Private Sub Form_Load()
Socket1.AddressFamily = AF_INET
Socket1.Protocol = IPPROTO_IP
Socket1.SocketType = SOCK_STREAM
Socket1.Binary = False
Socket1.BufferSize = 1024
Socket1.Blocking = False
Socket1.LocalPort = 5630
Socket1.Action = SOCKET_LISTEN
End Sub

And the client:

Code:
Private Sub Command1_Click()
On Error GoTo Failed
Socket1.HostName = Trim$(Text1.Text)
Socket1.RemotePort = 5630
Socket1.Action = SOCKET_CONNECT
Text2.Text = "Connected"
Text3.Enabled = True
Command2.Enabled = True
Exit Sub

Failed:
MsgBox "Unable to connect to remote host"
Exit Sub
End Sub

Private Sub Command2_Click()
Socket1.SendLen = Len(Text3.Text)
Socket1.SendData = Text3.Text
End Sub

Private Sub Form_Load()
Socket1.AddressFamily = AF_INET
Socket1.Protocol = IPPROTO_IP
Socket1.SocketType = SOCK_STREAM
Socket1.Binary = False
Socket1.Blocking = False
Socket1.BufferSize = 1024
End Sub

Private Sub Form_Unload(Cancel As Integer)
If Socket1.Connected Then Socket1.Action = SOCKET_CLOSE
End Sub

What am I doing wrong? I've tried searching the internet and Catalyst's website for examples on accepting just 1 connection, but can't find any. Thanks.

Socket Question
i would like to close socket connection when all the data have been received. how will i know if it is time to command socket.close?

thanks

Async Socket
Hi all,

Is there any way to implement asynchronous socket in visual basic?

Let me explain what I am trying to do.

I have a server component which talks with a device and collect details. Now instead of all systems doing this I am trying to use winsock so that only my server gathers the information and transmit it to all the system (clients) a same time.

How do I achieve this? I should have trouble of connecting to each client machine individually and transmit information thru the port. Instead I am looking for a way which would transmit the information to the system listening in a specific port.

Can anyone throw some light on this?

If anyone can point me to a tutorial or a sample code is greatly appreciated.

Thanks for having a look

Regards
Shiva

Hwnd Of Socket
I need to get a handle of socket which is used by another application.
For example:
My smtp server listens on port 25. I need to get a handle of its socket.
(on local)
(or i need to get application which is listening on this port - exact exe file)

Thanks

Which Varible Is Socket
I'm setting up my program using the Winsock API. All is fine, though, because my program manages a numerous amount of connections I need a way to determine which connection is being returned.

As it gets parsed back to WndProc (I hooked Winsock). I take it uMsg is WINSOCKMSG and lParam is the type of Winsock Message (eg, FD_CONENCT). Is wParam the Socket in which the message came from?

[edit] Nevermind, wParam is the Socket.

Raw Socket Question
What is wrong if


Code:
WSAIoctl(m_lngSocket, SIO_RCVALL, lngInBuffer, Len(lngInBuffer), lngOutBuffer, Len(lngOutBuffer), lngBytesReturned, ByVal 0, ByVal 0)
isn't 0 ?, i get a "WSAIoctl failed." error message.

The application that im trying to run is: http://pscode.com/vb/scripts/ShowCod...46567&lngWId=1
. I have no idea whatsoever why this error occures.

Cheers

VB6.0 Socket Programming
I need to do some socket programming using VB6.0 something like multithreading without using multithreading. Could someone please let me know of some books wesites... I have been searching but not much luck so far.

Socket Function
Is it possible to create a function to return a user's cookie using winsock? i.e. Have the function utilize the DataArrival event, and OnConnect event?

Socket Email
Hello,
I have been trying to send email with the Winsock control. To test it, I've just been trying to email myself. (I have the code shown below.) For some reason it can't seem to connect. When I wait for a response from the server upon attempt to connect, it eventually just times out. Any ideas why?
Thanks,
Meg

Option Explicit

Dim Response As String
Dim start_time As Single
Dim current_time As Single
Dim time_elapsed As Single
Private Sub Command1_Click()
send_email "student530-1", "student530-1", "meg", "bob", "mw86@cornell.edu", "mw86@cornell.edu", "hi", "test"
MsgBox "here"
End Sub
Private Sub tcpMailSocket_DataArrival(ByVal bytesTotal As Long)
tcpMailSocket.GetData Response
End Sub
Private Sub wait_for_response(code As String)

'get start time
start_time = Timer

'until there is a response
While Len(Response) = 0
'get the current time
current_time = Timer
'see how much time has elapsed
time_elapsed = Abs(current_time - start_time)
'keep checking for response from server
DoEvents
'if too much time has elapsed
If time_elapsed > 50 Then
MsgBox "SMTP service error, timed out while waiting for response", 64, "Server Timed Out"
Exit Sub
End If
Wend

'now we know server is responding something
'until we get the right response
While Left(Response, 3) <> code
'get the current time
current_time = Timer
'see how much time has elapsed
time_elapsed = Abs(current_time - start_time)
'keep checking for response from server
'keep waiting for correct response
DoEvents
If time_elapsed > 50 Then
MsgBox "SMTP service error, impromper response code. Code should have been: " + code + " Code recieved: " + Response, 64, "Wrong response from server"
Exit Sub
End If
Wend

End Sub
Private Sub send_email(my_name As String, server_name As String, from_name As String, to_name As String, from_address As String, to_address As String, subject As String, body As String)

Dim from_string As String
Dim current_date As String
Dim date_string As String
Dim email_string As String
Dim to_string As String
Dim subject_string As String

'make sure connection is closed. if not, close and open new connection
If tcpMailSocket.State <> sckClosed Then
tcpMailSocket.Close
End If

'use TCP protocol for sending
'tcpMailSocket.Protocol = sckTCPProtocol

'must set to 0 so you can send multiple emails per program starts
tcpMailSocket.LocalPort = 25

'remote server
tcpMailSocket.RemoteHost = my_name

'remote port is 25 for email
tcpMailSocket.RemotePort = 25

'connnect to other computer
tcpMailSocket.Connect

'wait for connection response
wait_for_response ("220")

'send handshake
tcpMailSocket.SendData ("HELO " & my_name & vbCrLf)

'wait for handshake response
wait_for_response ("250")

'send mail from and wait for response
tcpMailSocket.SendData ("mail from: " & from_address & vbCrLf)
wait_for_response ("250")

'send recipient and wait for response
tcpMailSocket.SendData ("rcpt to: " & to_address & vbCrLf)
wait_for_response ("250")

'send data tag and wait for a response
tcpMailSocket.SendData ("data" & vbCrLf)
wait_for_response ("354")

'send rest of email headers
from_string = "From: """ & from_name & """ <" & from_address & ">" & vbCrLf
current_date = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
date_string = "Date: " & current_date & vbCrLf
email_string = "X-Mailer: STMP Sender" & vbCrLf
to_string = "To: " & to_name & vbCrLf
subject_string = "Subject: " & subject & vbCrLf

tcpMailSocket.SendData (from_string & date_string & email_string & to_string & subject_string & vbCrLf)

'send email message and wait for a response
tcpMailSocket.SendData (body & vbCrLf & vbCrLf)
tcpMailSocket.SendData ("." & vbCrLf)
wait_for_response ("250")

'send quit and wait for response
tcpMailSocket.SendData ("quit" & vbCrLf)
wait_for_response ("221")

'close connection
tcpMailSocket.Close

End Sub

Socket Manipulation?
Is there any way to attatch a vb program to the socket of a browser. Im wanting to monitor all incoming and outgoing traffic of a browser. ie http headers, bytes transferred and such. Sorta like a spy type thing.
Any help would be appreciated, thanks!

Socket Programming
I'm trying to implement a simple program using socket programming with a client/server set up on the same computer in vb.net. But I'm unsure as to how I would send a file through to the client. Can anyone help me with this issue. Thanks

Command For Socket
i am newbie to vb.is there any command available to use to open a port.pls help me

IPHeader With Raw Socket?
Hello..

i'm currently using this source code:
http://www.pscode.com/vb/scripts/Sho...53191&lngWId=1

i was wondering.. since there is a sendpacket function, i've gave it a try.. but i can't.. i need to give an IPHeader.. i've tried to use the same as the one i was recieved on TCPDriver_RecievedPacket().. didn't work, i need to create my own..

How can i do that?

About Socket Programming In VB6
hi every one,

I am new to network programs using vb.but i ve experience in vb 6. i need very basic helps and directions to start a network programming in vb.
wat commands i need to use, wat are the functions i ve use. how to start coding..
help and suggestions are appreciable...

Socket Only Works Once
When my server program is executed from IDE, it only works once. If you exit from the program (but not from the IDE), the next time I get the following error:

Run-time error '10022':
Socket not bound, invalid address or listen is not invoked prior to accept

The strange thing is that if I try my program on different computers, all running Windows XP PRO SP2, VB6 SP6, Winsock Activex 6.0 version 6.01.9782, I will get that error all the time on some computers, while I will never get it on other computers. How can I fix this? Here is my server code:


VB Code:
' Components: Microsoft Winsock Control 6.0 (SP6) Private Sub Form_Load()     Winsock1.Protocol = sckTCPProtocol    Winsock1.LocalPort = 34401    Winsock1.Listen        MsgBox "Successfully opened socket in Listen mode!" End Sub

Simple Socket Example
I need a simple socket example for winsock in VB6, nothing to complicated. An actual example or prehaps a tutorial will be nice. Thanks!

Help With Socket Programming
I am using SocketWrench FreeWare Edition to make a server program. The client program sends mutiple lines of text from a .txt file to the server which then receives the data and saves it as a .txt file. In the socket's .Read function, I need to develop the code to make it receive the data as a .txt file. All I have right now is this:


VB Code:
Private Sub sockServer_Read(Index As Integer, DataLength As Integer, IsUrgent As Integer)sockServer(Index).Read strBuffer, DataLengthEnd Sub


I am confused what to do please help.

Socket Issue
VB Code:
Function IsServerOnline() As LongDim MySocket As LongMySocket = 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 IfEnd Function

It errors "Type mismatch" on the bold line on "server"

What am I doing wrong? (yes I have the API's declared)

Socket Question
wsckClient.SendData "hello"

the client sends data "hello" to the server, but how do i make it msgbox error if the server socket is offline??

or should i just put

On Error Resume Next, so it ust skips the error? (i dont really want to do this)

Socket Problem
I havent developed an VB6 Application that uses Sockets in a long time.

But anyway, I'm working on one atm and for some reason the Socket connects to the server every 1 in 5 tries. Now I think this might be some XP SP2 [removed by mod]. Does anyone have any idea?

BTW: Running this Server/Client app on same computer for testing. And I do have VB6 SP6 installed.

Thanks for the Help
Carsten

Hex To Text From A Socket
Hello,

I'm attempting to covert hex into text which is received from a socket(winsock). I'm really new to hex, although I've worked with HexWorkshop for editing hex. But now it comes to me... I have to convert the hex which is received though winsock.

Any help is greatly apreciated.

Socket Class
somewhere onthe net i saw a scoket class that could replace the std winsock component and it is better(?)

i cant find it anywhere anymore

SOCKET Or DirectPlay
Although this may seem strange but...

What do you think is better to use in a wireless network application, the usual scoket,TCP/IP or use functions and methods provided by DirectPlay 8 since it is said it support wireless Networks (I don't know realy how ) ?

Anything would help

Thanx in advance

Viewing The SSL Socket?
How do you view if the SSL Socket is activated in a Explorer Program... E.G. ( Iexplorer)..

Thanks in advance...

Problem With Socket
Hey guys,
I have a little question.
I just moved .NET, and I wanted to convert
my Gnutella client from 6.0 into .NET.
The automatic conversion sucked so I decided
to do the convertion on my own.

The thing I dont get is the System.Net.
Is there any premade Socket Class which has
EXACTLY the same features the Winsock had?
I mean features like Index Arrays, OnConnectionRequest,
OnConnect, OnDataArrival (with the same events etc)?

Help would be appreciated,
.NEt looks entirely different to me.

Socket Sniffer...
is it possible to make an app that listenes to the MSN messenger port, gets data that's sended but at the same time, forward that data to the client again? i need this cause i want to make something that checks for someone to have a window open for u.... thnx

Socket Calls With VB6
Does anyone know if VB can make socket calls?

I'm trying to implement tunneling, it requires the ability to
serialize objects over http.

if I can make socket connections & serialize objects I should be OK!

Thanks

J

Windows Socket
Dear all,

This is my requirement.

I am using a windows socket control which is in a Form.

Now only when there arrives a packet the form should be displayed.

Is this possible to implement?

Thanks in Advance
Aravind

Socket Testing
Quote:




Originally posted by bedowin
Is there a code I can execute on a particular server to see the max number of sockets available?

I have a winsock control that listens for connections on one port, and I want to know what the max number of sockets available will be, so I will then know if I need more than one server to handle the amount of concurrent connections.






Why not just check the index of the win sock control that will tell you how many connections there are or set a variable to allow max connection "intmax and display it somewhere and if the max is full have it increase. You get the poing

Copyright 2005-08 www.BigResource.com, All rights reserved