Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old November 10th, 2003, 06:14 AM
milind_sr milind_sr is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Pune
Posts: 3 milind_sr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
VB Socket programming(Server )

I am writing a server in Visual Basic using WINSOCK API.
This server creates a socket and listens at a particular port.
The client(C-PROGRAM) will connect to this server and send a rtf file which the server will collect and then the server will covert this rtf file to the ps(postscript) file and sent back to the client.

Here i am able to get client connection and also able to convert it to ps and send it back to the client. But this is possible only as a single threaded way. At a time only one client is possible to work with the server and if something goes wrong with any file the server program cannot move further . My requirement is that the server should work with multiple clients at a time.

Thus i did write write code in ActiveX EXE with exposed method which recieves the handle of a (client)socket gets the file and sends it back to the client.

the code that intitaites the Activex exe class is as follows
(only important steps have been pasted here )

'Call the accept Winsock API function in order to create a new socket after the clint connects the server

lngRetValue = accept(lngSocketHandle, udtSocketAddress, lngBufferSize)

'create an object of the ActiveX EXE class and then call one of its method which recieves the handle of the socket new clinet connection socket

Set ps_machine_obj = New ps_machine

ps_machine_obj.start_session lngRetValue


IN the ActiveX exe when the code tries to recieve the data on this socket handle by the following function


Private Function IsDataAvailable(lngSocket As Long) As Boolean
'
Dim udtRead_fd As fd_set
Dim udtWrite_fd As fd_set
Dim udtError_fd As fd_set

Dim lngSocketCount As Long
'
udtRead_fd.fd_count = 1
udtRead_fd.fd_array(1) = lngSocket
'

' MsgBox lngSocket
lngSocketCount = vbselect(0&, udtRead_fd, udtWrite_fd, udtError_fd, 0&)
'
IsDataAvailable = CBool(lngSocketCount)
'
'MsgBox WSAGetLastError

' ShowErrorMessage Err.LastDllError

End Function

the vbselect function returns -1.
I do not get as why does it generate the socket ERROR(-1).


if the same class is added in the project then it works fine.

(i am referring to this site URL)


Can any one help me......

Reply With Quote
  #2  
Old November 10th, 2003, 09:27 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
If u Note the referece page,u can found the difference between them:
Reference Sample:
...Function IsConnected(ByVal lngSocket As Long) As Boolean ...

Your code:
...Function IsDataAvailable(lngSocket As Long) As Boolean ...

Good luck!

Reply With Quote
  #3  
Old November 10th, 2003, 10:06 PM
milind_sr milind_sr is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Pune
Posts: 3 milind_sr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
cleverpig :
i tried it out both ways ByVal anf ByRef it doesn't work.
and i also had mentioned that the same class when i include in the project it works fine.

if things are not yet clear please ask me i will provide more details.

Reply With Quote
  #4  
Old November 10th, 2003, 10:55 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Your class is same as vbip web page??Can u give me the class work fine,maybe i can find something?!..How do u call the Is DataAvailable function with the parameters??

Reply With Quote
  #5  
Old November 11th, 2003, 07:17 AM
milind_sr milind_sr is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Pune
Posts: 3 milind_sr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Class code is attached:

The function that calls the class is as follows

Private Sub cmdAccept_Click()
'

Dim lngSocket As Long
Dim lngRetValue As Long
Dim objProtocol As CProtocol
Dim lvItem As ListItem
Dim ps_machine_obj As ps_machine

'
'Is there any selected socket in the listview contorl?
'If Not lvSockets.SelectedItem Is Nothing Then
'
'Get the socket handle
'lngSocket = CLng(lvSockets.SelectedItem.Text)
If Sockethandle.Text = "" Then
Exit Sub
End If

'Enable timer
Timer1.Enabled = True

lngSocket = Sockethandle.Text
'
'Call the vbAccept function in order to accept the
'connection request and create a new socket
lngRetValue = vbAccept(lngSocket)


'MsgBox "Accept : " & CStr(lngRetValue)

If lngRetValue = INVALID_SOCKET Then
'
'An error was occurred - show the error message
Call ShowErrorMessage(Err.LastDllError)
'
Else
'
'The vbAccept function has returned a valid socket
'handle. We need to add a new item into the listview
'control for the socket recently created by that function.
'
'Each item in the listview has several columns to display
'the socket's parameters. We can retrieve that parameters
'with CProtocol class.
'
'Create an instance of the CProtocol class


Set objProtocol = New CProtocol
Call objProtocol.GetBySocketHandle(lngRetValue)
'
'Add a new item into the listview
Set lvItem = lvSockets.ListItems.Add(, "S" & CStr(lngRetValue), lngRetValue, , 2)
'
'Add values for the socket properties' columns
' lvItem.SubItems(1) = cboAddressFamily.List(objProtocol.AddressFamily - 1)
' lvItem.SubItems(2) = cboSocketType.List(objProtocol.SocketType - 1)
' lvItem.SubItems(3) = cboProtocol.List(objProtocol.Protocol - 2)
' '

lvItem.SubItems(1) = cboAddressFamily.Text
lvItem.SubItems(2) = cboSocketType.Text
lvItem.SubItems(3) = cboProtocol.Text


'All the connected sockets are marked with a bold font
lvItem.Bold = True
'
End If '--> If lngRetValue = INVALID_SOCKET Then
'
' End If '--> If Not lvSockets.SelectedItem Is Nothing Then
'
Set objProtocol = Nothing

Set ps_machine_obj = New ps_machine

ps_machine_obj.start_session lngRetValue

Set ps_machine_obj = Nothing


'While Not IsDataAvailable(lngSocket)
' Sleep (2000)
'Wend


'
End Sub
Attached Files
File Type: txt class_ps_machine.txt (18.9 KB, 255 views)

Reply With Quote
  #6  
Old November 11th, 2003, 06:47 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Difference between Byval and Byref:
Passing Arguments ByVal or ByRef
Arguments can be passed ByRef (the default) or ByVal. ByRef passes a reference to the actual data item; ByVal passes a copy of the data.
When you pass a value to a procedure you may pass it ByVal or ByRef (for by value or by reference).
ByVal sends a copy of the argument’s value to the procedure.
You would use the ByVal when you do not want the procedure to alter the original value. ByRef sends a reference indicating where the value is stored in memory.
You would use ByRef when you want the called procedure to actually change the argument's original value.
You can specify how you want to pass the argument by using the ByVal or ByRef keyword before the argument. If you don't specify ByVal or ByRef, arguments are passed by reference..

So i think u should modify this statement"lngSocketCount = vbselect(0&, udtRead_fd, udtWrite_fd, udtError_fd, 0&)" to "lngSocketCount = vbselect(0, udtRead_fd&, udtWrite_fd&, udtError_fd&, 0)"

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > VB Socket programming(Server )


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway