- 积分
- 66
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-9-2
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
program server
use KERNEL32
use WS2_32
implicit none
integer WINSOCK_V2_2 !版本
integer connection_dropped_by_remote_party
integer success
parameter(WINSOCK_V2_2=X'202',connection_dropped_by_remote_party=X'05050505',success=0)
type(T_SOCKADDR_IN) listenerInfo !Server_add
type(T_SOCKADDR_IN) connectionInfo !client_add
type(T_WSADATA) wsaInfo !版本信息结构
type T_client_server_message
union
map
integer receivelen
integer sendlen
end map
map
character*(100) receivebuffer
character*(100) sendbuffer
end map
end union
end type
type(T_client_server_message)ClientServerMessage
integer connection !socket_receive
integer listener !socket_server
character*(15) host
integer*2 port
integer SendMsg !send()
integer ReceiveMsg !recv()
integer status
! Initialize Winsock v2.
status=WSAStartup(WINSOCK_V2_2,wasInfo)
if(status.NE.success)then
write(*,*)'WSAStartup-',status
stop
end if
! 创建套接字
listener=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)
if(listener.EQ.INVALID_SOCKET) then
write(*,*)'socket-',INVALID_SOCKET
status=WSACleanup()
stop
end if
! 设置连接地址
host='0.0.0.0'
port=55000
listenerInfo%sin_family=AF_INET
listenerInfo%sin_port=htons(port)
listenerInfo%sin_addr%s_addr =inet_addr(host(1:LEN_TRIM(host)))
! 绑定套接字到某地的某个地址和端口
status=bind(listener,%REF(listenerInfo),sizeof(listenerInfo))
if(status.EQ.SOCKET_ERROR) then
write(*,*)'bind -',WSAGetLastError()
status = WSACleanup()
stop
end if
!监听状态
do while(.true.)
status = listen(listener,1)
if(status<0)then
write(*,*)'listen -'
status=WSACleanup()
stop
end if
!接受连接
if (status.EQ.SUCCESS) then
connection=SOCKET_ERROR
do while(connection.EQ.SOCKET_ERROR)
connection=accept(listener,%REF(connectionInfo),0)
call sleep(100)
end do
!进行聊天
!接收数据
do while(.true.)
clientServerMessage%receivelen=recv(connection,clientServerMessage%receivebuffer,100,0)
if(clientServerMessage%receivelen<0)then
write(*,*)"接受失败,程序退出"
stop
else
write(*,*)"client say:",clientServerMessage%receivebuffer
end if
!发送数据
write(*,*)"please enter message:"
read(*,*) clientServerMessage%sendbuffer
clientServerMessage%sendlen=send(connection,clientServerMessage%sendbuffer,100,0)
if(clientServerMessage%sendlen<0)then
write(*,*)"发送失败"
end if
end do
end if
end do
status =closesocket(connection)
status =closesocket(listener)
status =WSACleanup()
pause
stop
end
错误 26 Compilation Aborted (code 1) d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 1
警告 19 warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL. [LEN_TRIM] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 58
错误 18 error #6514: A substring must be of type CHARACTER. [HOST] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 58
错误 25 error #6460: This is not a field name that is defined in the encompassing structure. [SENDLEN] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 102
错误 24 error #6460: This is not a field name that is defined in the encompassing structure. [SENDBUFFER] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 101
错误 22 error #6460: This is not a field name that is defined in the encompassing structure. [RECEIVELEN] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 92
错误 23 error #6460: This is not a field name that is defined in the encompassing structure. [RECEIVEBUFFER] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 92
错误 14 error #6404: This name does not have a type, and must have an explicit type. [WASINFO] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 37
错误 13 error #6404: This name does not have a type, and must have an explicit type. [STATUS] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 37
错误 17 error #6404: This name does not have a type, and must have an explicit type. [PORT] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 54
错误 15 error #6404: This name does not have a type, and must have an explicit type. [LISTENER] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 44
错误 20 error #6404: This name does not have a type, and must have an explicit type. [LEN_TRIM] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 58
错误 16 error #6404: This name does not have a type, and must have an explicit type. [HOST] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 53
错误 21 error #6404: This name does not have a type, and must have an explicit type. [CONNECTION] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 80
错误 12 error #6404: This name does not have a type, and must have an explicit type. [CLIENTSERVERMESSAGE] d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 27
错误 4 error #6386: Confused statement; this is neither a valid I/O TYPE stmt, nor a valid F90 derived-type-stmt, nor a valid F90 type-declaration-stmt. d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 27
错误 5 error #6236: A specification statement cannot appear in the executable section. d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 28
错误 6 error #6236: A specification statement cannot appear in the executable section. d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 29
错误 7 error #6236: A specification statement cannot appear in the executable section. d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 30
错误 8 error #6236: A specification statement cannot appear in the executable section. d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 31
错误 9 error #6236: A specification statement cannot appear in the executable section. d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 32
错误 10 error #6236: A specification statement cannot appear in the executable section. d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 33
错误 11 error #6236: A specification statement cannot appear in the executable section. d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 34
错误 3 error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( * ) . % + - [ . ** / // d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 27
错误 1 error #5078: Unrecognized token 'T_client_server_message?' skipped d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 27
错误 2 error #5078: Unrecognized token '?' skipped d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90 27
|
|